History

Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi

Pull SCSI updates from James Bottomley: "This update includes the usual round of major driver updates (ncr5380, ufs, lpfc, be2iscsi, hisi_sas, storvsc, cxlflash, aacraid, megaraid_sas, ...). There's also an assortment of minor fixes and the major update of switching a bunch of drivers to pci_alloc_irq_vectors from Christoph" * tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: (188 commits) scsi: megaraid_sas: handle dma_addr_t right on 32-bit scsi: megaraid_sas: array overflow in megasas_dump_frame() scsi: snic: switch to pci_irq_alloc_vectors scsi: megaraid_sas: driver version upgrade scsi: megaraid_sas: Change RAID_1_10_RMW_CMDS to RAID_1_PEER_CMDS and set value to 2 scsi: megaraid_sas: Indentation and smatch warning fixes scsi: megaraid_sas: Cleanup VD_EXT_DEBUG and SPAN_DEBUG related debug prints scsi: megaraid_sas: Increase internal command pool scsi: megaraid_sas: Use synchronize_irq to wait for IRQs to complete scsi: megaraid_sas: Bail out the driver load if ld_list_query fails scsi: megaraid_sas: Change build_mpt_mfi_pass_thru to return void scsi: megaraid_sas: During OCR, if get_ctrl_info fails do not continue with OCR scsi: megaraid_sas: Do not set fp_possible if TM capable for non-RW syspdIO, change fp_possible to bool scsi: megaraid_sas: Remove unused pd_index from megasas_build_ld_nonrw_fusion scsi: megaraid_sas: megasas_return_cmd does not memset IO frame to zero scsi: megaraid_sas: max_fw_cmds are decremented twice, remove duplicate scsi: megaraid_sas: update can_queue only if the new value is less scsi: megaraid_sas: Change max_cmd from u32 to u16 in all functions scsi: megaraid_sas: set pd_after_lb from MR_BuildRaidContext and initialize pDevHandle to MR_DEVHANDLE_INVALID scsi: megaraid_sas: latest controller OCR capability from FW before sending shutdown DCMD ...

Linus Torvalds committed 9 years ago

Commit cdc19472 parents 772c8f6 d1da522129 files · +9294 −3928Browse files

Unified · Split

129 files
  1. drivers/ata/libata-eh.c +1 −0
  2. drivers/ata/libata-transport.c +0 −1
  3. drivers/ata/libata.h +0 −1
  4. drivers/block/cciss.h +15 −15
  5. drivers/infiniband/ulp/iser/iscsi_iser.c +1 −0
  6. drivers/infiniband/ulp/srp/ib_srp.c +1 −0
  7. drivers/message/fusion/mptfc.c +1 −0
  8. drivers/message/fusion/mptlan.h +0 −1
  9. drivers/message/fusion/mptsas.c +1 −1
  10. drivers/s390/scsi/zfcp_scsi.c +1 −0
  11. drivers/scsi/NCR5380.c +22 −42
  12. drivers/scsi/NCR5380.h +1 −16
  13. drivers/scsi/aacraid/aachba.c +962 −326
  14. drivers/scsi/aacraid/aacraid.h +568 −76
  15. drivers/scsi/aacraid/commctrl.c +271 −71
  16. drivers/scsi/aacraid/comminit.c +190 −140
  17. drivers/scsi/aacraid/commsup.c +705 −259
  18. drivers/scsi/aacraid/dpcsup.c +103 −56
  19. drivers/scsi/aacraid/linit.c +387 −175
  20. drivers/scsi/aacraid/nark.c +2 −1
  21. drivers/scsi/aacraid/rkt.c +3 −2
  22. drivers/scsi/aacraid/rx.c +10 −7
  23. drivers/scsi/aacraid/sa.c +5 −4
  24. drivers/scsi/aacraid/src.c +246 −90
  25. drivers/scsi/atari_scsi.c +3 −33
  26. drivers/scsi/be2iscsi/be.h +0 −3
  27. drivers/scsi/be2iscsi/be_cmds.c +22 −19
  28. drivers/scsi/be2iscsi/be_cmds.h +9 −8
  29. drivers/scsi/be2iscsi/be_iscsi.c +83 −82
  30. drivers/scsi/be2iscsi/be_main.c +157 −188
  31. drivers/scsi/be2iscsi/be_main.h +10 −34
  32. drivers/scsi/be2iscsi/be_mgmt.c +66 −51
  33. drivers/scsi/be2iscsi/be_mgmt.h +17 −81
  34. drivers/scsi/bfa/bfa_fcs.c +46 −135
  35. drivers/scsi/bfa/bfa_fcs.h +0 −4
  36. drivers/scsi/bfa/bfad_im.c +2 −0
  37. drivers/scsi/bnx2fc/bnx2fc_fcoe.c +1 −0
  38. drivers/scsi/bnx2i/bnx2i_iscsi.c +1 −0
  39. drivers/scsi/csiostor/csio_scsi.c +2 −0
  40. drivers/scsi/cxgbi/cxgb3i/cxgb3i.c +1 −0
  41. drivers/scsi/cxgbi/cxgb4i/cxgb4i.c +1 −0
  42. drivers/scsi/cxlflash/common.h +28 −4
  43. drivers/scsi/cxlflash/lunmgt.c +18 −13
  44. drivers/scsi/cxlflash/main.c +264 −201
  45. drivers/scsi/cxlflash/sislite.h +18 −1
  46. drivers/scsi/cxlflash/superpipe.c +99 −84
  47. drivers/scsi/cxlflash/vlun.c +90 −79
  48. drivers/scsi/dpt_i2o.c +2 −6
  49. drivers/scsi/esas2r/esas2r_init.c +1 −1
  50. drivers/scsi/esas2r/esas2r_ioctl.c +1 −1
  51. drivers/scsi/esas2r/esas2r_log.h +2 −2
  52. drivers/scsi/esas2r/esas2r_main.c +2 −2
  53. drivers/scsi/fcoe/fcoe.c +1 −0
  54. drivers/scsi/fnic/fnic_main.c +1 −0
  55. drivers/scsi/g_NCR5380.c +43 −2
  56. drivers/scsi/g_NCR5380.h +0 −56
  57. drivers/scsi/hisi_sas/hisi_sas.h +1 −0
  58. drivers/scsi/hisi_sas/hisi_sas_main.c +13 −10
  59. drivers/scsi/hisi_sas/hisi_sas_v1_hw.c +2 −0
  60. drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +116 −19
  61. drivers/scsi/hpsa.c +2 −6
  62. drivers/scsi/hpsa.h +20 −20
  63. drivers/scsi/ibmvscsi/ibmvfc.c +1 −0
  64. drivers/scsi/ibmvscsi/ibmvscsi.c +1 −0
  65. drivers/scsi/iscsi_tcp.c +1 −0
  66. drivers/scsi/libiscsi.c +2 −3
  67. drivers/scsi/libsas/sas_init.c +0 −1
  68. drivers/scsi/libsas/sas_internal.h +0 −2
  69. drivers/scsi/libsas/sas_scsi_host.c +0 −7
  70. drivers/scsi/lpfc/lpfc.h +0 −1
  71. drivers/scsi/lpfc/lpfc_attr.c +41 −20
  72. drivers/scsi/lpfc/lpfc_crtn.h +4 −3
  73. drivers/scsi/lpfc/lpfc_els.c +7 −2
  74. drivers/scsi/lpfc/lpfc_hw.h +6 −0
  75. drivers/scsi/lpfc/lpfc_scsi.c +14 −6
  76. drivers/scsi/lpfc/lpfc_sli.c +9 −4
  77. drivers/scsi/lpfc/lpfc_version.h +1 −1
  78. drivers/scsi/lpfc/lpfc_vport.c +8 −0
  79. drivers/scsi/mac_scsi.c +4 −4
  80. drivers/scsi/megaraid/megaraid_sas.h +153 −46
  81. drivers/scsi/megaraid/megaraid_sas_base.c +488 −160
  82. drivers/scsi/megaraid/megaraid_sas_fp.c +231 −237
  83. drivers/scsi/megaraid/megaraid_sas_fusion.c +1080 −254
  84. drivers/scsi/megaraid/megaraid_sas_fusion.h +376 −36
  85. drivers/scsi/mpt3sas/mpi/mpi2_ioc.h +2 −0
  86. drivers/scsi/mpt3sas/mpt3sas_base.c +20 −0
  87. drivers/scsi/mpt3sas/mpt3sas_base.h +4 −3
  88. drivers/scsi/mpt3sas/mpt3sas_ctl.c +3 −1
  89. drivers/scsi/mpt3sas/mpt3sas_scsih.c +45 −11
  90. drivers/scsi/mvumi.c +1 −5
  91. drivers/scsi/pm8001/pm8001_init.c +14 −21
  92. drivers/scsi/pm8001/pm8001_sas.h +0 −2
  93. drivers/scsi/pmcraid.c +41 −51
  94. drivers/scsi/pmcraid.h +0 −1
  95. drivers/scsi/qedi/qedi_dbg.c +6 −3
  96. drivers/scsi/qedi/qedi_iscsi.c +1 −4
  97. drivers/scsi/qla2xxx/qla_def.h +2 −2
  98. drivers/scsi/qla2xxx/qla_gs.c +3 −3
  99. drivers/scsi/qla2xxx/qla_isr.c +5 −5
  100. drivers/scsi/qla2xxx/qla_os.c +1 −0
  101. drivers/scsi/qla4xxx/ql4_def.h +0 −3
  102. drivers/scsi/qla4xxx/ql4_os.c +3 −3
  103. drivers/scsi/scsi_debug.c +9 −1
  104. drivers/scsi/scsi_error.c +1 −3
  105. drivers/scsi/scsi_transport_fc.c +4 −22
  106. drivers/scsi/scsi_transport_srp.c +2 −19
  107. drivers/scsi/sd.c +2 −2
  108. drivers/scsi/snic/snic.h +0 −1
  109. drivers/scsi/snic/snic_isr.c +19 −29
  110. drivers/scsi/storvsc_drv.c +140 −20
  111. drivers/scsi/sun3_scsi.c +79 −4
  112. drivers/scsi/sun3_scsi.h +0 −102
  113. drivers/scsi/ufs/ufs-qcom.c +43 −6
  114. drivers/scsi/ufs/ufs-qcom.h +1 −0
  115. drivers/scsi/ufs/ufs.h +12 −0
  116. drivers/scsi/ufs/ufs_quirks.h +6 −22
  117. drivers/scsi/ufs/ufshcd.c +1337 −241
  118. drivers/scsi/ufs/ufshcd.h +110 −11
  119. drivers/scsi/ufs/ufshci.h +3 −0
  120. drivers/scsi/vmw_pvscsi.c +38 −66
  121. drivers/scsi/vmw_pvscsi.h +0 −5
  122. include/linux/libata.h +2 −0
  123. include/scsi/libiscsi.h +1 −0
  124. include/scsi/scsi.h +0 −10
  125. include/scsi/scsi_transport.h +0 −23
  126. include/scsi/scsi_transport_fc.h +1 −0
  127. include/scsi/scsi_transport_srp.h +1 −7
  128. include/trace/events/ufs.h +263 −0
  129. include/uapi/scsi/cxlflash_ioctl.h +1 −0
drivers/ata/libata-eh.c+1−0
@@ -549,6 +549,7 @@ enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd) · 548 unmodified lines
549549 DPRINTK("EXIT, ret=%d\n", ret);
550550 return ret;
551551 }
552+EXPORT_SYMBOL(ata_scsi_timed_out);
552553
553554 static void ata_eh_unload(struct ata_port *ap)
554555 {
drivers/ata/libata-transport.c+0−1
@@ -716,7 +716,6 @@ struct scsi_transport_template *ata_attach_transport(void) · 715 unmodified lines
716716 return NULL;
717717
718718 i->t.eh_strategy_handler = ata_scsi_error;
719− i->t.eh_timed_out = ata_scsi_timed_out;
720719 i->t.user_scan = ata_scsi_user_scan;
721720
722721 i->t.host_attrs.ac.attrs = &i->port_attrs[0];
drivers/ata/libata.h+0−1
@@ -159,7 +159,6 @@ extern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd); · 158 unmodified lines
159159 extern void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd);
160160 extern void ata_eh_acquire(struct ata_port *ap);
161161 extern void ata_eh_release(struct ata_port *ap);
162−extern enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
163162 extern void ata_scsi_error(struct Scsi_Host *host);
164163 extern void ata_eh_fastdrain_timerfn(unsigned long arg);
165164 extern void ata_qc_schedule_eh(struct ata_queued_cmd *qc);
drivers/block/cciss.h+15−15
@@ -400,27 +400,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h) · 399 unmodified lines
400400 }
401401
402402 static struct access_method SA5_access = {
403− SA5_submit_command,
404− SA5_intr_mask,
405− SA5_fifo_full,
406− SA5_intr_pending,
407− SA5_completed,
403+ .submit_command = SA5_submit_command,
404+ .set_intr_mask = SA5_intr_mask,
405+ .fifo_full = SA5_fifo_full,
406+ .intr_pending = SA5_intr_pending,
407+ .command_completed = SA5_completed,
408408 };
409409
410410 static struct access_method SA5B_access = {
411− SA5_submit_command,
412− SA5B_intr_mask,
413− SA5_fifo_full,
414− SA5B_intr_pending,
415− SA5_completed,
411+ .submit_command = SA5_submit_command,
412+ .set_intr_mask = SA5B_intr_mask,
413+ .fifo_full = SA5_fifo_full,
414+ .intr_pending = SA5B_intr_pending,
415+ .command_completed = SA5_completed,
416416 };
417417
418418 static struct access_method SA5_performant_access = {
419− SA5_submit_command,
420− SA5_performant_intr_mask,
421− SA5_fifo_full,
422− SA5_performant_intr_pending,
423− SA5_performant_completed,
419+ .submit_command = SA5_submit_command,
420+ .set_intr_mask = SA5_performant_intr_mask,
421+ .fifo_full = SA5_fifo_full,
422+ .intr_pending = SA5_performant_intr_pending,
423+ .command_completed = SA5_performant_completed,
424424 };
425425
426426 struct board_type {
drivers/infiniband/ulp/iser/iscsi_iser.c+1−0
@@ -994,6 +994,7 @@ static struct scsi_host_template iscsi_iser_sht = { · 993 unmodified lines
994994 .change_queue_depth = scsi_change_queue_depth,
995995 .sg_tablesize = ISCSI_ISER_DEF_SG_TABLESIZE,
996996 .cmd_per_lun = ISER_DEF_CMD_PER_LUN,
997+ .eh_timed_out = iscsi_eh_cmd_timed_out,
997998 .eh_abort_handler = iscsi_eh_abort,
998999 .eh_device_reset_handler= iscsi_eh_device_reset,
9991000 .eh_target_reset_handler = iscsi_eh_recover_target,
drivers/infiniband/ulp/srp/ib_srp.c+1−0
@@ -2869,6 +2869,7 @@ static struct scsi_host_template srp_template = { · 2868 unmodified lines
28692869 .info = srp_target_info,
28702870 .queuecommand = srp_queuecommand,
28712871 .change_queue_depth = srp_change_queue_depth,
2872+ .eh_timed_out = srp_timed_out,
28722873 .eh_abort_handler = srp_abort,
28732874 .eh_device_reset_handler = srp_reset_device,
28742875 .eh_host_reset_handler = srp_reset_host,
drivers/message/fusion/mptfc.c+1−0
@@ -119,6 +119,7 @@ static struct scsi_host_template mptfc_driver_template = { · 118 unmodified lines
119119 .target_destroy = mptfc_target_destroy,
120120 .slave_destroy = mptscsih_slave_destroy,
121121 .change_queue_depth = mptscsih_change_queue_depth,
122+ .eh_timed_out = fc_eh_timed_out,
122123 .eh_abort_handler = mptfc_abort,
123124 .eh_device_reset_handler = mptfc_dev_reset,
124125 .eh_bus_reset_handler = mptfc_bus_reset,
drivers/message/fusion/mptlan.h+0−1
@@ -65,7 +65,6 @@ · 64 unmodified lines
6565 #include <linux/init.h>
6666 #include <linux/kernel.h>
6767 #include <linux/slab.h>
68−#include <linux/miscdevice.h>
6968 #include <linux/spinlock.h>
7069 #include <linux/workqueue.h>
7170 #include <linux/delay.h>
drivers/message/fusion/mptsas.c+1−1
@@ -1983,6 +1983,7 @@ static struct scsi_host_template mptsas_driver_template = { · 1982 unmodified lines
19831983 .target_destroy = mptsas_target_destroy,
19841984 .slave_destroy = mptscsih_slave_destroy,
19851985 .change_queue_depth = mptscsih_change_queue_depth,
1986+ .eh_timed_out = mptsas_eh_timed_out,
19861987 .eh_abort_handler = mptscsih_abort,
19871988 .eh_device_reset_handler = mptscsih_dev_reset,
19881989 .eh_host_reset_handler = mptscsih_host_reset,
@@ -5398,7 +5399,6 @@ mptsas_init(void) · 3409 unmodified lines
53985399 sas_attach_transport(&mptsas_transport_functions);
53995400 if (!mptsas_transport_template)
54005401 return -ENODEV;
5401− mptsas_transport_template->eh_timed_out = mptsas_eh_timed_out;
54025402
54035403 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER,
54045404 "mptscsih_io_done");
drivers/s390/scsi/zfcp_scsi.c+1−0
@@ -330,6 +330,7 @@ static struct scsi_host_template zfcp_scsi_host_template = { · 329 unmodified lines
330330 .module = THIS_MODULE,
331331 .name = "zfcp",
332332 .queuecommand = zfcp_scsi_queuecommand,
333+ .eh_timed_out = fc_eh_timed_out,
333334 .eh_abort_handler = zfcp_scsi_eh_abort_handler,
334335 .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
335336 .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
drivers/scsi/NCR5380.c+22−42
@@ -96,17 +96,6 @@ · 95 unmodified lines
9696 * of chips. To use it, you write an architecture specific functions
9797 * and macros and include this file in your driver.
9898 *
99− * These macros control options :
100− * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
101− * for commands that return with a CHECK CONDITION status.
102− *
103− * DIFFERENTIAL - if defined, NCR53c81 chips will use external differential
104− * transceivers.
105− *
106− * PSEUDO_DMA - if defined, PSEUDO DMA is used during the data transfer phases.
107− *
108− * REAL_DMA - if defined, REAL DMA is used during the data transfer phases.
109− *
11099 * These macros MUST be defined :
111100 *
112101 * NCR5380_read(register) - read from the specified register
@@ -347,7 +336,7 @@ static void NCR5380_print_phase(struct Scsi_Host *instance) · 234 unmodified lines
347336 #endif
348337
349338 /**
350− * NCR58380_info - report driver and host information
339+ * NCR5380_info - report driver and host information
351340 * @instance: relevant scsi host instance
352341 *
353342 * For use as the host template info() handler.
@@ -360,33 +349,6 @@ static const char *NCR5380_info(struct Scsi_Host *instance) · 6 unmodified lines
360349 return hostdata->info;
361350 }
362351
363−static void prepare_info(struct Scsi_Host *instance)
364−{
365− struct NCR5380_hostdata *hostdata = shost_priv(instance);
366−
367− snprintf(hostdata->info, sizeof(hostdata->info),
368− "%s, irq %d, "
369− "io_port 0x%lx, base 0x%lx, "
370− "can_queue %d, cmd_per_lun %d, "
371− "sg_tablesize %d, this_id %d, "
372− "flags { %s%s%s}, "
373− "options { %s} ",
374− instance->hostt->name, instance->irq,
375− hostdata->io_port, hostdata->base,
376− instance->can_queue, instance->cmd_per_lun,
377− instance->sg_tablesize, instance->this_id,
378− hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "",
379− hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "",
380− hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : "",
381−#ifdef DIFFERENTIAL
382− "DIFFERENTIAL "
383−#endif
384−#ifdef PARITY
385− "PARITY "
386−#endif
387− "");
388−}
389−
390352 /**
391353 * NCR5380_init - initialise an NCR5380
392354 * @instance: adapter to configure
@@ -436,7 +398,14 @@ static int NCR5380_init(struct Scsi_Host *instance, int flags) · 43 unmodified lines
436398 if (!hostdata->work_q)
437399 return -ENOMEM;
438400
439− prepare_info(instance);
401+ snprintf(hostdata->info, sizeof(hostdata->info),
402+ "%s, irq %d, io_port 0x%lx, base 0x%lx, can_queue %d, cmd_per_lun %d, sg_tablesize %d, this_id %d, flags { %s%s%s}",
403+ instance->hostt->name, instance->irq, hostdata->io_port,
404+ hostdata->base, instance->can_queue, instance->cmd_per_lun,
405+ instance->sg_tablesize, instance->this_id,
406+ hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "",
407+ hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "",
408+ hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : "");
440409
441410 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
442411 NCR5380_write(MODE_REG, MR_BASE);
@@ -622,8 +591,9 @@ static inline void maybe_release_dma_irq(struct Scsi_Host *instance) · 179 unmodified lines
622591 list_empty(&hostdata->unissued) &&
623592 list_empty(&hostdata->autosense) &&
624593 !hostdata->connected &&
625− !hostdata->selecting)
594+ !hostdata->selecting) {
626595 NCR5380_release_dma_irq(instance);
596+ }
627597 }
628598
629599 /**
@@ -962,6 +932,7 @@ static irqreturn_t __maybe_unused NCR5380_intr(int irq, void *dev_id) · 332 unmodified lines
962932
963933 static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance,
964934 struct scsi_cmnd *cmd)
935+ __releases(&hostdata->lock) __acquires(&hostdata->lock)
965936 {
966937 struct NCR5380_hostdata *hostdata = shost_priv(instance);
967938 unsigned char tmp[3], phase;
@@ -1194,8 +1165,16 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance, · 226 unmodified lines
11941165 data = tmp;
11951166 phase = PHASE_MSGOUT;
11961167 NCR5380_transfer_pio(instance, &phase, &len, &data);
1168+ if (len) {
1169+ NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1170+ cmd->result = DID_ERROR << 16;
1171+ complete_cmd(instance, cmd);
1172+ dsprintk(NDEBUG_SELECTION, instance, "IDENTIFY message transfer failed\n");
1173+ cmd = NULL;
1174+ goto out;
1175+ }
1176+
11971177 dsprintk(NDEBUG_SELECTION, instance, "nexus established.\n");
1198− /* XXX need to handle errors here */
11991178
12001179 hostdata->connected = cmd;
12011180 hostdata->busy[cmd->device->id] |= 1 << cmd->device->lun;
@@ -1654,6 +1633,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance, · 452 unmodified lines
16541633 */
16551634
16561635 static void NCR5380_information_transfer(struct Scsi_Host *instance)
1636+ __releases(&hostdata->lock) __acquires(&hostdata->lock)
16571637 {
16581638 struct NCR5380_hostdata *hostdata = shost_priv(instance);
16591639 unsigned char msgout = NOP;
drivers/scsi/NCR5380.h+1−16
@@ -81,11 +81,7 @@ · 80 unmodified lines
8181 #define ICR_ASSERT_ATN 0x02 /* rw Set to assert ATN */
8282 #define ICR_ASSERT_DATA 0x01 /* rw SCSI_DATA_REG is asserted */
8383
84−#ifdef DIFFERENTIAL
85−#define ICR_BASE ICR_DIFF_ENABLE
86−#else
8784 #define ICR_BASE 0
88−#endif
8985
9086 #define MODE_REG 2
9187 /*
@@ -102,11 +98,7 @@ · 10 unmodified lines
10298 #define MR_DMA_MODE 0x02 /* rw DMA / pseudo DMA mode */
10399 #define MR_ARBITRATE 0x01 /* rw start arbitration */
104100
105−#ifdef PARITY
106−#define MR_BASE MR_ENABLE_PAR_CHECK
107−#else
108101 #define MR_BASE 0
109−#endif
110102
111103 #define TARGET_COMMAND_REG 3
112104 #define TCR_LAST_BYTE_SENT 0x80 /* ro DMA done */
@@ -174,11 +166,7 @@ · 61 unmodified lines
174166 #define CSR_SCSI_BUF_RDY 0x02 /* ro SCSI buffer read */
175167 #define CSR_GATED_53C80_IRQ 0x01 /* ro Last block xferred */
176168
177−#if 0
178−#define CSR_BASE CSR_SCSI_BUFF_INTR | CSR_53C80_INTR
179−#else
180169 #define CSR_BASE CSR_53C80_INTR
181−#endif
182170
183171 /* Note : PHASE_* macros are based on the values of the STATUS register */
184172 #define PHASE_MASK (SR_MSG | SR_CD | SR_IO)
@@ -234,11 +222,9 @@ struct NCR5380_hostdata { · 49 unmodified lines
234222 unsigned char id_higher_mask; /* All bits above id_mask */
235223 unsigned char last_message; /* Last Message Out */
236224 unsigned long region_size; /* Size of address/port range */
237− char info[256];
225+ char info[168]; /* Host banner message */
238226 };
239227
240−#ifdef __KERNEL__
241−
242228 struct NCR5380_cmd {
243229 struct list_head list;
244230 };
@@ -331,5 +317,4 @@ static inline int NCR5380_dma_residual_none(struct NCR5380_hostdata *hostdata) · 86 unmodified lines
331317 return 0;
332318 }
333319
334−#endif /* __KERNEL__ */
335320 #endif /* NCR5380_H */
drivers/scsi/aacraid/aachba.c+962−326
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -22,6 +23,11 @@ · 9 unmodified lines
2223 * along with this program; see the file COPYING. If not, write to
2324 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
2425 *
26+ * Module Name:
27+ * aachba.c
28+ *
29+ * Abstract: Contains Interfaces to manage IOs.
30+ *
2531 */
2632
2733 #include <linux/kernel.h>
@@ -62,6 +68,7 @@ · 34 unmodified lines
6268 #define SENCODE_END_OF_DATA 0x00
6369 #define SENCODE_BECOMING_READY 0x04
6470 #define SENCODE_INIT_CMD_REQUIRED 0x04
71+#define SENCODE_UNRECOVERED_READ_ERROR 0x11
6572 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
6673 #define SENCODE_INVALID_COMMAND 0x20
6774 #define SENCODE_LBA_OUT_OF_RANGE 0x21
@@ -106,6 +113,8 @@ · 38 unmodified lines
106113 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
107114 #define ASENCODE_OVERLAPPED_COMMAND 0x00
108115
116+#define AAC_STAT_GOOD (DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD)
117+
109118 #define BYTE0(x) (unsigned char)(x)
110119 #define BYTE1(x) (unsigned char)((x) >> 8)
111120 #define BYTE2(x) (unsigned char)((x) >> 16)
@@ -164,46 +173,56 @@ struct inquiry_data { · 52 unmodified lines
164173 };
165174
166175 /* Added for VPD 0x83 */
167−typedef struct {
168− u8 CodeSet:4; /* VPD_CODE_SET */
169− u8 Reserved:4;
170− u8 IdentifierType:4; /* VPD_IDENTIFIER_TYPE */
171− u8 Reserved2:4;
172− u8 Reserved3;
173− u8 IdentifierLength;
174− u8 VendId[8];
175− u8 ProductId[16];
176− u8 SerialNumber[8]; /* SN in ASCII */
177−
178−} TVPD_ID_Descriptor_Type_1;
176+struct tvpd_id_descriptor_type_1 {
177+ u8 codeset:4; /* VPD_CODE_SET */
178+ u8 reserved:4;
179+ u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
180+ u8 reserved2:4;
181+ u8 reserved3;
182+ u8 identifierlength;
183+ u8 venid[8];
184+ u8 productid[16];
185+ u8 serialnumber[8]; /* SN in ASCII */
179186
180−typedef struct {
181− u8 CodeSet:4; /* VPD_CODE_SET */
182− u8 Reserved:4;
183− u8 IdentifierType:4; /* VPD_IDENTIFIER_TYPE */
184− u8 Reserved2:4;
185− u8 Reserved3;
186− u8 IdentifierLength;
187− struct TEU64Id {
187+};
188+
189+struct tvpd_id_descriptor_type_2 {
190+ u8 codeset:4; /* VPD_CODE_SET */
191+ u8 reserved:4;
192+ u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
193+ u8 reserved2:4;
194+ u8 reserved3;
195+ u8 identifierlength;
196+ struct teu64id {
188197 u32 Serial;
189198 /* The serial number supposed to be 40 bits,
190199 * bit we only support 32, so make the last byte zero. */
191− u8 Reserved;
192− u8 VendId[3];
193− } EU64Id;
200+ u8 reserved;
201+ u8 venid[3];
202+ } eu64id;
194203
195−} TVPD_ID_Descriptor_Type_2;
204+};
196205
197−typedef struct {
206+struct tvpd_id_descriptor_type_3 {
207+ u8 codeset : 4; /* VPD_CODE_SET */
208+ u8 reserved : 4;
209+ u8 identifiertype : 4; /* VPD_IDENTIFIER_TYPE */
210+ u8 reserved2 : 4;
211+ u8 reserved3;
212+ u8 identifierlength;
213+ u8 Identifier[16];
214+};
215+
216+struct tvpd_page83 {
198217 u8 DeviceType:5;
199218 u8 DeviceTypeQualifier:3;
200219 u8 PageCode;
201− u8 Reserved;
220+ u8 reserved;
202221 u8 PageLength;
203− TVPD_ID_Descriptor_Type_1 IdDescriptorType1;
204− TVPD_ID_Descriptor_Type_2 IdDescriptorType2;
205−
206−} TVPD_Page83;
222+ struct tvpd_id_descriptor_type_1 type1;
223+ struct tvpd_id_descriptor_type_2 type2;
224+ struct tvpd_id_descriptor_type_3 type3;
225+};
207226
208227 /*
209228 * M O D U L E G L O B A L S
@@ -214,9 +233,13 @@ static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg); · 4 unmodified lines
214233 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
215234 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
216235 struct aac_raw_io2 *rio2, int sg_max);
236+static long aac_build_sghba(struct scsi_cmnd *scsicmd,
237+ struct aac_hba_cmd_req *hbacmd,
238+ int sg_max, u64 sg_address);
217239 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
218240 int pages, int nseg, int nseg_new);
219241 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
242+static int aac_send_hba_fib(struct scsi_cmnd *scsicmd);
220243 #ifdef AAC_DETAILED_STATUS_INFO
221244 static char *aac_get_status_string(u32 status);
222245 #endif
@@ -327,7 +350,7 @@ static inline int aac_valid_context(struct scsi_cmnd *scsicmd, · 104 unmodified lines
327350 }
328351 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
329352 device = scsicmd->device;
330− if (unlikely(!device || !scsi_device_online(device))) {
353+ if (unlikely(!device)) {
331354 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
332355 aac_fib_complete(fibptr);
333356 return 0;
@@ -473,16 +496,26 @@ int aac_get_containers(struct aac_dev *dev) · 139 unmodified lines
473496
474497 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
475498 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
476− fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
477− GFP_KERNEL);
478− if (!fsa_dev_ptr)
479− return -ENOMEM;
499+ if (dev->fsa_dev == NULL ||
500+ dev->maximum_num_containers != maximum_num_containers) {
501+
502+ fsa_dev_ptr = dev->fsa_dev;
503+
504+ dev->fsa_dev = kcalloc(maximum_num_containers,
505+ sizeof(*fsa_dev_ptr), GFP_KERNEL);
506+
507+ kfree(fsa_dev_ptr);
508+ fsa_dev_ptr = NULL;
480509
481− dev->fsa_dev = fsa_dev_ptr;
482− dev->maximum_num_containers = maximum_num_containers;
483510
484− for (index = 0; index < dev->maximum_num_containers; ) {
485− fsa_dev_ptr[index].devname[0] = '\0';
511+ if (!dev->fsa_dev)
512+ return -ENOMEM;
513+
514+ dev->maximum_num_containers = maximum_num_containers;
515+ }
516+ for (index = 0; index < dev->maximum_num_containers; index++) {
517+ dev->fsa_dev[index].devname[0] = '\0';
518+ dev->fsa_dev[index].valid = 0;
486519
487520 status = aac_probe_container(dev, index);
488521
@@ -490,12 +523,6 @@ int aac_get_containers(struct aac_dev *dev) · 1 unmodified line
490523 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
491524 break;
492525 }
493−
494− /*
495− * If there are no more containers, then stop asking.
496− */
497− if (++index >= status)
498− break;
499526 }
500527 return status;
501528 }
@@ -602,6 +629,7 @@ static void _aac_probe_container2(void * context, struct fib * fibptr) · 100 unmodified lines
602629 struct fsa_dev_info *fsa_dev_ptr;
603630 int (*callback)(struct scsi_cmnd *);
604631 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
632+ int i;
605633
606634
607635 if (!aac_valid_context(scsicmd, fibptr))
@@ -624,6 +652,10 @@ static void _aac_probe_container2(void * context, struct fib * fibptr) · 16 unmodified lines
624652 fsa_dev_ptr->block_size =
625653 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
626654 }
655+ for (i = 0; i < 16; i++)
656+ fsa_dev_ptr->identifier[i] =
657+ dresp->mnt[0].fileinfo.bdevinfo
658+ .identifier[i];
627659 fsa_dev_ptr->valid = 1;
628660 /* sense_key holds the current state of the spin-up */
629661 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
@@ -918,6 +950,28 @@ static void setinqstr(struct aac_dev *dev, void *data, int tindex) · 288 unmodified lines
918950 inqstrcpy ("V1.0", str->prl);
919951 }
920952
953+static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
954+ struct aac_dev *dev, struct scsi_cmnd *scsicmd)
955+{
956+ int container;
957+
958+ vpdpage83data->type3.codeset = 1;
959+ vpdpage83data->type3.identifiertype = 3;
960+ vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
961+ - 4;
962+
963+ for (container = 0; container < dev->maximum_num_containers;
964+ container++) {
965+
966+ if (scmd_id(scsicmd) == container) {
967+ memcpy(vpdpage83data->type3.Identifier,
968+ dev->fsa_dev[container].identifier,
969+ 16);
970+ break;
971+ }
972+ }
973+}
974+
921975 static void get_container_serial_callback(void *context, struct fib * fibptr)
922976 {
923977 struct aac_get_serial_resp * get_serial_reply;
@@ -935,39 +989,47 @@ static void get_container_serial_callback(void *context, struct fib * fibptr) · 11 unmodified lines
935989 /*Check to see if it's for VPD 0x83 or 0x80 */
936990 if (scsicmd->cmnd[2] == 0x83) {
937991 /* vpd page 0x83 - Device Identification Page */
992+ struct aac_dev *dev;
938993 int i;
939− TVPD_Page83 VPDPage83Data;
994+ struct tvpd_page83 vpdpage83data;
995+
996+ dev = (struct aac_dev *)scsicmd->device->host->hostdata;
940997
941− memset(((u8 *)&VPDPage83Data), 0,
942− sizeof(VPDPage83Data));
998+ memset(((u8 *)&vpdpage83data), 0,
999+ sizeof(vpdpage83data));
9431000
9441001 /* DIRECT_ACCESS_DEVIC */
945− VPDPage83Data.DeviceType = 0;
1002+ vpdpage83data.DeviceType = 0;
9461003 /* DEVICE_CONNECTED */
947− VPDPage83Data.DeviceTypeQualifier = 0;
1004+ vpdpage83data.DeviceTypeQualifier = 0;
9481005 /* VPD_DEVICE_IDENTIFIERS */
949− VPDPage83Data.PageCode = 0x83;
950− VPDPage83Data.Reserved = 0;
951− VPDPage83Data.PageLength =
952− sizeof(VPDPage83Data.IdDescriptorType1) +
953− sizeof(VPDPage83Data.IdDescriptorType2);
1006+ vpdpage83data.PageCode = 0x83;
1007+ vpdpage83data.reserved = 0;
1008+ vpdpage83data.PageLength =
1009+ sizeof(vpdpage83data.type1) +
1010+ sizeof(vpdpage83data.type2);
1011+
1012+ /* VPD 83 Type 3 is not supported for ARC */
1013+ if (dev->sa_firmware)
1014+ vpdpage83data.PageLength +=
1015+ sizeof(vpdpage83data.type3);
9541016
9551017 /* T10 Vendor Identifier Field Format */
956− /* VpdCodeSetAscii */
957− VPDPage83Data.IdDescriptorType1.CodeSet = 2;
1018+ /* VpdcodesetAscii */
1019+ vpdpage83data.type1.codeset = 2;
9581020 /* VpdIdentifierTypeVendorId */
959− VPDPage83Data.IdDescriptorType1.IdentifierType = 1;
960− VPDPage83Data.IdDescriptorType1.IdentifierLength =
961− sizeof(VPDPage83Data.IdDescriptorType1) - 4;
1021+ vpdpage83data.type1.identifiertype = 1;
1022+ vpdpage83data.type1.identifierlength =
1023+ sizeof(vpdpage83data.type1) - 4;
9621024
9631025 /* "ADAPTEC " for adaptec */
964− memcpy(VPDPage83Data.IdDescriptorType1.VendId,
1026+ memcpy(vpdpage83data.type1.venid,
9651027 "ADAPTEC ",
966− sizeof(VPDPage83Data.IdDescriptorType1.VendId));
967− memcpy(VPDPage83Data.IdDescriptorType1.ProductId,
1028+ sizeof(vpdpage83data.type1.venid));
1029+ memcpy(vpdpage83data.type1.productid,
9681030 "ARRAY ",
9691031 sizeof(
970− VPDPage83Data.IdDescriptorType1.ProductId));
1032+ vpdpage83data.type1.productid));
9711033
9721034 /* Convert to ascii based serial number.
9731035 * The LSB is the the end.
@@ -976,32 +1038,41 @@ static void get_container_serial_callback(void *context, struct fib * fibptr) · 2 unmodified lines
9761038 u8 temp =
9771039 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
9781040 if (temp > 0x9) {
979− VPDPage83Data.IdDescriptorType1.SerialNumber[i] =
1041+ vpdpage83data.type1.serialnumber[i] =
9801042 'A' + (temp - 0xA);
9811043 } else {
982− VPDPage83Data.IdDescriptorType1.SerialNumber[i] =
1044+ vpdpage83data.type1.serialnumber[i] =
9831045 '0' + temp;
9841046 }
9851047 }
9861048
9871049 /* VpdCodeSetBinary */
988− VPDPage83Data.IdDescriptorType2.CodeSet = 1;
989− /* VpdIdentifierTypeEUI64 */
990− VPDPage83Data.IdDescriptorType2.IdentifierType = 2;
991− VPDPage83Data.IdDescriptorType2.IdentifierLength =
992− sizeof(VPDPage83Data.IdDescriptorType2) - 4;
1050+ vpdpage83data.type2.codeset = 1;
1051+ /* VpdidentifiertypeEUI64 */
1052+ vpdpage83data.type2.identifiertype = 2;
1053+ vpdpage83data.type2.identifierlength =
1054+ sizeof(vpdpage83data.type2) - 4;
9931055
994− VPDPage83Data.IdDescriptorType2.EU64Id.VendId[0] = 0xD0;
995− VPDPage83Data.IdDescriptorType2.EU64Id.VendId[1] = 0;
996− VPDPage83Data.IdDescriptorType2.EU64Id.VendId[2] = 0;
1056+ vpdpage83data.type2.eu64id.venid[0] = 0xD0;
1057+ vpdpage83data.type2.eu64id.venid[1] = 0;
1058+ vpdpage83data.type2.eu64id.venid[2] = 0;
9971059
998− VPDPage83Data.IdDescriptorType2.EU64Id.Serial =
1060+ vpdpage83data.type2.eu64id.Serial =
9991061 get_serial_reply->uid;
1000− VPDPage83Data.IdDescriptorType2.EU64Id.Reserved = 0;
1062+ vpdpage83data.type2.eu64id.reserved = 0;
1063+
1064+ /*
1065+ * VpdIdentifierTypeFCPHName
1066+ * VPD 0x83 Type 3 not supported for ARC
1067+ */
1068+ if (dev->sa_firmware) {
1069+ build_vpd83_type3(&vpdpage83data,
1070+ dev, scsicmd);
1071+ }
10011072
10021073 /* Move the inquiry data to the response buffer. */
1003− scsi_sg_copy_from_buffer(scsicmd, &VPDPage83Data,
1004− sizeof(VPDPage83Data));
1074+ scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
1075+ sizeof(vpdpage83data));
10051076 } else {
10061077 /* It must be for VPD 0x80 */
10071078 char sp[13];
@@ -1144,7 +1215,9 @@ static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u3 · 136 unmodified lines
11441215 long ret;
11451216
11461217 aac_fib_init(fib);
1147− if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1218+ if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1219+ dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1220+ !dev->sync_mode) {
11481221 struct aac_raw_io2 *readcmd2;
11491222 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
11501223 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
@@ -1270,7 +1343,9 @@ static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u · 119 unmodified lines
12701343 long ret;
12711344
12721345 aac_fib_init(fib);
1273− if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1346+ if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1347+ dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1348+ !dev->sync_mode) {
12741349 struct aac_raw_io2 *writecmd2;
12751350 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
12761351 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
@@ -1435,6 +1510,52 @@ static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd · 158 unmodified lines
14351510 return srbcmd;
14361511 }
14371512
1513+static struct aac_hba_cmd_req *aac_construct_hbacmd(struct fib *fib,
1514+ struct scsi_cmnd *cmd)
1515+{
1516+ struct aac_hba_cmd_req *hbacmd;
1517+ struct aac_dev *dev;
1518+ int bus, target;
1519+ u64 address;
1520+
1521+ dev = (struct aac_dev *)cmd->device->host->hostdata;
1522+
1523+ hbacmd = (struct aac_hba_cmd_req *)fib->hw_fib_va;
1524+ memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
1525+ /* iu_type is a parameter of aac_hba_send */
1526+ switch (cmd->sc_data_direction) {
1527+ case DMA_TO_DEVICE:
1528+ hbacmd->byte1 = 2;
1529+ break;
1530+ case DMA_FROM_DEVICE:
1531+ case DMA_BIDIRECTIONAL:
1532+ hbacmd->byte1 = 1;
1533+ break;
1534+ case DMA_NONE:
1535+ default:
1536+ break;
1537+ }
1538+ hbacmd->lun[1] = cpu_to_le32(cmd->device->lun);
1539+
1540+ bus = aac_logical_to_phys(scmd_channel(cmd));
1541+ target = scmd_id(cmd);
1542+ hbacmd->it_nexus = dev->hba_map[bus][target].rmw_nexus;
1543+
1544+ /* we fill in reply_qid later in aac_src_deliver_message */
1545+ /* we fill in iu_type, request_id later in aac_hba_send */
1546+ /* we fill in emb_data_desc_count later in aac_build_sghba */
1547+
1548+ memcpy(hbacmd->cdb, cmd->cmnd, cmd->cmd_len);
1549+ hbacmd->data_length = cpu_to_le32(scsi_bufflen(cmd));
1550+
1551+ address = (u64)fib->hw_error_pa;
1552+ hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
1553+ hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
1554+ hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
1555+
1556+ return hbacmd;
1557+}
1558+
14381559 static void aac_srb_callback(void *context, struct fib * fibptr);
14391560
14401561 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
@@ -1505,11 +1626,243 @@ static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd) · 64 unmodified lines
15051626 return aac_scsi_32(fib, cmd);
15061627 }
15071628
1629+static int aac_adapter_hba(struct fib *fib, struct scsi_cmnd *cmd)
1630+{
1631+ struct aac_hba_cmd_req *hbacmd = aac_construct_hbacmd(fib, cmd);
1632+ struct aac_dev *dev;
1633+ long ret;
1634+
1635+ dev = (struct aac_dev *)cmd->device->host->hostdata;
1636+
1637+ ret = aac_build_sghba(cmd, hbacmd,
1638+ dev->scsi_host_ptr->sg_tablesize, (u64)fib->hw_sgl_pa);
1639+ if (ret < 0)
1640+ return ret;
1641+
1642+ /*
1643+ * Now send the HBA command to the adapter
1644+ */
1645+ fib->hbacmd_size = 64 + le32_to_cpu(hbacmd->emb_data_desc_count) *
1646+ sizeof(struct aac_hba_sgl);
1647+
1648+ return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, fib,
1649+ (fib_callback) aac_hba_callback,
1650+ (void *) cmd);
1651+}
1652+
1653+int aac_issue_bmic_identify(struct aac_dev *dev, u32 bus, u32 target)
1654+{
1655+ struct fib *fibptr;
1656+ struct aac_srb *srbcmd;
1657+ struct sgmap64 *sg64;
1658+ struct aac_ciss_identify_pd *identify_resp;
1659+ dma_addr_t addr;
1660+ u32 vbus, vid;
1661+ u16 fibsize, datasize;
1662+ int rcode = -ENOMEM;
1663+
1664+
1665+ fibptr = aac_fib_alloc(dev);
1666+ if (!fibptr)
1667+ goto out;
1668+
1669+ fibsize = sizeof(struct aac_srb) -
1670+ sizeof(struct sgentry) + sizeof(struct sgentry64);
1671+ datasize = sizeof(struct aac_ciss_identify_pd);
1672+
1673+ identify_resp = pci_alloc_consistent(dev->pdev, datasize, &addr);
1674+
1675+ if (!identify_resp)
1676+ goto fib_free_ptr;
1677+
1678+ vbus = (u32)le16_to_cpu(dev->supplement_adapter_info.VirtDeviceBus);
1679+ vid = (u32)le16_to_cpu(dev->supplement_adapter_info.VirtDeviceTarget);
1680+
1681+ aac_fib_init(fibptr);
1682+
1683+ srbcmd = (struct aac_srb *) fib_data(fibptr);
1684+ srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1685+ srbcmd->channel = cpu_to_le32(vbus);
1686+ srbcmd->id = cpu_to_le32(vid);
1687+ srbcmd->lun = 0;
1688+ srbcmd->flags = cpu_to_le32(SRB_DataIn);
1689+ srbcmd->timeout = cpu_to_le32(10);
1690+ srbcmd->retry_limit = 0;
1691+ srbcmd->cdb_size = cpu_to_le32(12);
1692+ srbcmd->count = cpu_to_le32(datasize);
1693+
1694+ memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1695+ srbcmd->cdb[0] = 0x26;
1696+ srbcmd->cdb[2] = (u8)((AAC_MAX_LUN + target) & 0x00FF);
1697+ srbcmd->cdb[6] = CISS_IDENTIFY_PHYSICAL_DEVICE;
1698+
1699+ sg64 = (struct sgmap64 *)&srbcmd->sg;
1700+ sg64->count = cpu_to_le32(1);
1701+ sg64->sg[0].addr[1] = cpu_to_le32((u32)(((addr) >> 16) >> 16));
1702+ sg64->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
1703+ sg64->sg[0].count = cpu_to_le32(datasize);
1704+
1705+ rcode = aac_fib_send(ScsiPortCommand64,
1706+ fibptr, fibsize, FsaNormal, 1, 1, NULL, NULL);
1707+
1708+ if (identify_resp->current_queue_depth_limit <= 0 ||
1709+ identify_resp->current_queue_depth_limit > 32)
1710+ dev->hba_map[bus][target].qd_limit = 32;
1711+ else
1712+ dev->hba_map[bus][target].qd_limit =
1713+ identify_resp->current_queue_depth_limit;
1714+
1715+ pci_free_consistent(dev->pdev, datasize, (void *)identify_resp, addr);
1716+
1717+ aac_fib_complete(fibptr);
1718+
1719+fib_free_ptr:
1720+ aac_fib_free(fibptr);
1721+out:
1722+ return rcode;
1723+}
1724+
1725+/**
1726+ * aac_update hba_map()- update current hba map with data from FW
1727+ * @dev: aac_dev structure
1728+ * @phys_luns: FW information from report phys luns
1729+ *
1730+ * Update our hba map with the information gathered from the FW
1731+ */
1732+void aac_update_hba_map(struct aac_dev *dev,
1733+ struct aac_ciss_phys_luns_resp *phys_luns, int rescan)
1734+{
1735+ /* ok and extended reporting */
1736+ u32 lun_count, nexus;
1737+ u32 i, bus, target;
1738+ u8 expose_flag, attribs;
1739+ u8 devtype;
1740+
1741+ lun_count = ((phys_luns->list_length[0] << 24)
1742+ + (phys_luns->list_length[1] << 16)
1743+ + (phys_luns->list_length[2] << 8)
1744+ + (phys_luns->list_length[3])) / 24;
1745+
1746+ for (i = 0; i < lun_count; ++i) {
1747+
1748+ bus = phys_luns->lun[i].level2[1] & 0x3f;
1749+ target = phys_luns->lun[i].level2[0];
1750+ expose_flag = phys_luns->lun[i].bus >> 6;
1751+ attribs = phys_luns->lun[i].node_ident[9];
1752+ nexus = *((u32 *) &phys_luns->lun[i].node_ident[12]);
1753+
1754+ if (bus >= AAC_MAX_BUSES || target >= AAC_MAX_TARGETS)
1755+ continue;
1756+
1757+ dev->hba_map[bus][target].expose = expose_flag;
1758+
1759+ if (expose_flag != 0) {
1760+ devtype = AAC_DEVTYPE_RAID_MEMBER;
1761+ goto update_devtype;
1762+ }
1763+
1764+ if (nexus != 0 && (attribs & 8)) {
1765+ devtype = AAC_DEVTYPE_NATIVE_RAW;
1766+ dev->hba_map[bus][target].rmw_nexus =
1767+ nexus;
1768+ } else
1769+ devtype = AAC_DEVTYPE_ARC_RAW;
1770+
1771+ if (devtype != AAC_DEVTYPE_NATIVE_RAW)
1772+ goto update_devtype;
1773+
1774+ if (aac_issue_bmic_identify(dev, bus, target) < 0)
1775+ dev->hba_map[bus][target].qd_limit = 32;
1776+
1777+update_devtype:
1778+ if (rescan == AAC_INIT)
1779+ dev->hba_map[bus][target].devtype = devtype;
1780+ else
1781+ dev->hba_map[bus][target].new_devtype = devtype;
1782+ }
1783+}
1784+
1785+/**
1786+ * aac_report_phys_luns() Process topology change
1787+ * @dev: aac_dev structure
1788+ * @fibptr: fib pointer
1789+ *
1790+ * Execute a CISS REPORT PHYS LUNS and process the results into
1791+ * the current hba_map.
1792+ */
1793+int aac_report_phys_luns(struct aac_dev *dev, struct fib *fibptr, int rescan)
1794+{
1795+ int fibsize, datasize;
1796+ struct aac_ciss_phys_luns_resp *phys_luns;
1797+ struct aac_srb *srbcmd;
1798+ struct sgmap64 *sg64;
1799+ dma_addr_t addr;
1800+ u32 vbus, vid;
1801+ int rcode = 0;
1802+
1803+ /* Thor SA Firmware -> CISS_REPORT_PHYSICAL_LUNS */
1804+ fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry)
1805+ + sizeof(struct sgentry64);
1806+ datasize = sizeof(struct aac_ciss_phys_luns_resp)
1807+ + (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun);
1808+
1809+ phys_luns = (struct aac_ciss_phys_luns_resp *) pci_alloc_consistent(
1810+ dev->pdev, datasize, &addr);
1811+
1812+ if (phys_luns == NULL) {
1813+ rcode = -ENOMEM;
1814+ goto err_out;
1815+ }
1816+
1817+ vbus = (u32) le16_to_cpu(
1818+ dev->supplement_adapter_info.VirtDeviceBus);
1819+ vid = (u32) le16_to_cpu(
1820+ dev->supplement_adapter_info.VirtDeviceTarget);
1821+
1822+ aac_fib_init(fibptr);
1823+
1824+ srbcmd = (struct aac_srb *) fib_data(fibptr);
1825+ srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1826+ srbcmd->channel = cpu_to_le32(vbus);
1827+ srbcmd->id = cpu_to_le32(vid);
1828+ srbcmd->lun = 0;
1829+ srbcmd->flags = cpu_to_le32(SRB_DataIn);
1830+ srbcmd->timeout = cpu_to_le32(10);
1831+ srbcmd->retry_limit = 0;
1832+ srbcmd->cdb_size = cpu_to_le32(12);
1833+ srbcmd->count = cpu_to_le32(datasize);
1834+
1835+ memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1836+ srbcmd->cdb[0] = CISS_REPORT_PHYSICAL_LUNS;
1837+ srbcmd->cdb[1] = 2; /* extended reporting */
1838+ srbcmd->cdb[8] = (u8)(datasize >> 8);
1839+ srbcmd->cdb[9] = (u8)(datasize);
1840+
1841+ sg64 = (struct sgmap64 *) &srbcmd->sg;
1842+ sg64->count = cpu_to_le32(1);
1843+ sg64->sg[0].addr[1] = cpu_to_le32(upper_32_bits(addr));
1844+ sg64->sg[0].addr[0] = cpu_to_le32(lower_32_bits(addr));
1845+ sg64->sg[0].count = cpu_to_le32(datasize);
1846+
1847+ rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize,
1848+ FsaNormal, 1, 1, NULL, NULL);
1849+
1850+ /* analyse data */
1851+ if (rcode >= 0 && phys_luns->resp_flag == 2) {
1852+ /* ok and extended reporting */
1853+ aac_update_hba_map(dev, phys_luns, rescan);
1854+ }
1855+
1856+ pci_free_consistent(dev->pdev, datasize, (void *) phys_luns, addr);
1857+err_out:
1858+ return rcode;
1859+}
1860+
15081861 int aac_get_adapter_info(struct aac_dev* dev)
15091862 {
15101863 struct fib* fibptr;
15111864 int rcode;
1512− u32 tmp;
1865+ u32 tmp, bus, target;
15131866 struct aac_adapter_info *info;
15141867 struct aac_bus_info *command;
15151868 struct aac_bus_info_response *bus_info;
@@ -1540,6 +1893,7 @@ int aac_get_adapter_info(struct aac_dev* dev) · 24 unmodified lines
15401893 }
15411894 memcpy(&dev->adapter_info, info, sizeof(*info));
15421895
1896+ dev->supplement_adapter_info.VirtDeviceBus = 0xffff;
15431897 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
15441898 struct aac_supplement_adapter_info * sinfo;
15451899
@@ -1567,6 +1921,13 @@ int aac_get_adapter_info(struct aac_dev* dev) · 21 unmodified lines
15671921
15681922 }
15691923
1924+ /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
1925+ for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
1926+ for (target = 0; target < AAC_MAX_TARGETS; target++) {
1927+ dev->hba_map[bus][target].devtype = 0;
1928+ dev->hba_map[bus][target].qd_limit = 0;
1929+ }
1930+ }
15701931
15711932 /*
15721933 * GetBusInfo
@@ -1599,6 +1960,12 @@ int aac_get_adapter_info(struct aac_dev* dev) · 26 unmodified lines
15991960 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
16001961 }
16011962
1963+ if (!dev->sync_mode && dev->sa_firmware &&
1964+ dev->supplement_adapter_info.VirtDeviceBus != 0xffff) {
1965+ /* Thor SA Firmware -> CISS_REPORT_PHYSICAL_LUNS */
1966+ rcode = aac_report_phys_luns(dev, fibptr, AAC_INIT);
1967+ }
1968+
16021969 if (!dev->in_reset) {
16031970 char buffer[16];
16041971 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
@@ -1765,6 +2132,11 @@ int aac_get_adapter_info(struct aac_dev* dev) · 160 unmodified lines
17652132 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
17662133 }
17672134 }
2135+ if (!dev->sync_mode && dev->sa_firmware &&
2136+ dev->scsi_host_ptr->sg_tablesize > HBA_MAX_SG_SEPARATE)
2137+ dev->scsi_host_ptr->sg_tablesize = dev->sg_tablesize =
2138+ HBA_MAX_SG_SEPARATE;
2139+
17682140 /* FIB should be freed only after getting the response from the F/W */
17692141 if (rcode != -ERESTARTSYS) {
17702142 aac_fib_complete(fibptr);
@@ -1845,6 +2217,15 @@ static void io_callback(void *context, struct fib * fibptr) · 74 unmodified lines
18452217 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
18462218 SCSI_SENSE_BUFFERSIZE));
18472219 break;
2220+ case ST_MEDERR:
2221+ scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2222+ SAM_STAT_CHECK_CONDITION;
2223+ set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
2224+ SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
2225+ memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2226+ min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2227+ SCSI_SENSE_BUFFERSIZE));
2228+ break;
18482229 default:
18492230 #ifdef AAC_DETAILED_STATUS_INFO
18502231 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
@@ -2312,7 +2693,7 @@ static int aac_start_stop(struct scsi_cmnd *scsicmd) · 461 unmodified lines
23122693
23132694 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
23142695 {
2315− u32 cid;
2696+ u32 cid, bus;
23162697 struct Scsi_Host *host = scsicmd->device->host;
23172698 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
23182699 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
@@ -2330,8 +2711,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 11 unmodified lines
23302711 if((cid >= dev->maximum_num_containers) ||
23312712 (scsicmd->device->lun != 0)) {
23322713 scsicmd->result = DID_NO_CONNECT << 16;
2333− scsicmd->scsi_done(scsicmd);
2334− return 0;
2714+ goto scsi_done_ret;
23352715 }
23362716
23372717 /*
@@ -2359,15 +2739,30 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 21 unmodified lines
23592739 }
23602740 }
23612741 } else { /* check for physical non-dasd devices */
2362− if (dev->nondasd_support || expose_physicals ||
2363− dev->jbod) {
2742+ bus = aac_logical_to_phys(scmd_channel(scsicmd));
2743+ if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2744+ (dev->hba_map[bus][cid].expose
2745+ == AAC_HIDE_DISK)){
2746+ if (scsicmd->cmnd[0] == INQUIRY) {
2747+ scsicmd->result = DID_NO_CONNECT << 16;
2748+ goto scsi_done_ret;
2749+ }
2750+ }
2751+
2752+ if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2753+ dev->hba_map[bus][cid].devtype
2754+ == AAC_DEVTYPE_NATIVE_RAW) {
2755+ if (dev->in_reset)
2756+ return -1;
2757+ return aac_send_hba_fib(scsicmd);
2758+ } else if (dev->nondasd_support || expose_physicals ||
2759+ dev->jbod) {
23642760 if (dev->in_reset)
23652761 return -1;
23662762 return aac_send_srb_fib(scsicmd);
23672763 } else {
23682764 scsicmd->result = DID_NO_CONNECT << 16;
2369− scsicmd->scsi_done(scsicmd);
2370− return 0;
2765+ goto scsi_done_ret;
23712766 }
23722767 }
23732768 }
@@ -2385,13 +2780,34 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 11 unmodified lines
23852780 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
23862781 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
23872782 SCSI_SENSE_BUFFERSIZE));
2388− scsicmd->scsi_done(scsicmd);
2389− return 0;
2783+ goto scsi_done_ret;
23902784 }
23912785
2392−
2393− /* Handle commands here that don't really require going out to the adapter */
23942786 switch (scsicmd->cmnd[0]) {
2787+ case READ_6:
2788+ case READ_10:
2789+ case READ_12:
2790+ case READ_16:
2791+ if (dev->in_reset)
2792+ return -1;
2793+ return aac_read(scsicmd);
2794+
2795+ case WRITE_6:
2796+ case WRITE_10:
2797+ case WRITE_12:
2798+ case WRITE_16:
2799+ if (dev->in_reset)
2800+ return -1;
2801+ return aac_write(scsicmd);
2802+
2803+ case SYNCHRONIZE_CACHE:
2804+ if (((aac_cache & 6) == 6) && dev->cache_protected) {
2805+ scsicmd->result = AAC_STAT_GOOD;
2806+ break;
2807+ }
2808+ /* Issue FIB to tell Firmware to flush it's cache */
2809+ if ((aac_cache & 6) != 2)
2810+ return aac_synchronize(scsicmd);
23952811 case INQUIRY:
23962812 {
23972813 struct inquiry_data inq_data;
@@ -2414,8 +2830,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 16 unmodified lines
24142830 arr[1] = scsicmd->cmnd[2];
24152831 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
24162832 sizeof(inq_data));
2417− scsicmd->result = DID_OK << 16 |
2418− COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2833+ scsicmd->result = AAC_STAT_GOOD;
24192834 } else if (scsicmd->cmnd[2] == 0x80) {
24202835 /* unit serial number page */
24212836 arr[3] = setinqserial(dev, &arr[4],
@@ -2426,8 +2841,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 4 unmodified lines
24262841 if (aac_wwn != 2)
24272842 return aac_get_container_serial(
24282843 scsicmd);
2429− scsicmd->result = DID_OK << 16 |
2430− COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2844+ scsicmd->result = AAC_STAT_GOOD;
24312845 } else if (scsicmd->cmnd[2] == 0x83) {
24322846 /* vpd page 0x83 - Device Identification Page */
24332847 char *sno = (char *)&inq_data;
@@ -2436,8 +2850,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 2 unmodified lines
24362850 if (aac_wwn != 2)
24372851 return aac_get_container_serial(
24382852 scsicmd);
2439− scsicmd->result = DID_OK << 16 |
2440− COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2853+ scsicmd->result = AAC_STAT_GOOD;
24412854 } else {
24422855 /* vpd page not implemented */
24432856 scsicmd->result = DID_OK << 16 |
@@ -2452,8 +2865,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 8 unmodified lines
24522865 sizeof(dev->fsa_dev[cid].sense_data),
24532866 SCSI_SENSE_BUFFERSIZE));
24542867 }
2455− scsicmd->scsi_done(scsicmd);
2456− return 0;
2868+ break;
24572869 }
24582870 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
24592871 inq_data.inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
@@ -2469,9 +2881,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 9 unmodified lines
24692881 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
24702882 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
24712883 sizeof(inq_data));
2472− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2473− scsicmd->scsi_done(scsicmd);
2474− return 0;
2884+ scsicmd->result = AAC_STAT_GOOD;
2885+ break;
24752886 }
24762887 if (dev->in_reset)
24772888 return -1;
@@ -2519,10 +2930,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 41 unmodified lines
25192930 /* Do not cache partition table for arrays */
25202931 scsicmd->device->removable = 1;
25212932
2522− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2523− scsicmd->scsi_done(scsicmd);
2524−
2525− return 0;
2933+ scsicmd->result = AAC_STAT_GOOD;
2934+ break;
25262935 }
25272936
25282937 case READ_CAPACITY:
@@ -2547,11 +2956,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 18 unmodified lines
25472956 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
25482957 /* Do not cache partition table for arrays */
25492958 scsicmd->device->removable = 1;
2550− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2551− SAM_STAT_GOOD;
2552− scsicmd->scsi_done(scsicmd);
2553−
2554− return 0;
2959+ scsicmd->result = AAC_STAT_GOOD;
2960+ break;
25552961 }
25562962
25572963 case MODE_SENSE:
@@ -2629,10 +3035,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 71 unmodified lines
26293035 scsi_sg_copy_from_buffer(scsicmd,
26303036 (char *)&mpd,
26313037 mode_buf_length);
2632− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2633− scsicmd->scsi_done(scsicmd);
2634−
2635− return 0;
3038+ scsicmd->result = AAC_STAT_GOOD;
3039+ break;
26363040 }
26373041 case MODE_SENSE_10:
26383042 {
@@ -2708,18 +3112,17 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 69 unmodified lines
27083112 (char *)&mpd10,
27093113 mode_buf_length);
27103114
2711− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2712− scsicmd->scsi_done(scsicmd);
2713−
2714− return 0;
3115+ scsicmd->result = AAC_STAT_GOOD;
3116+ break;
27153117 }
27163118 case REQUEST_SENSE:
27173119 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2718− memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2719− memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2720− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2721− scsicmd->scsi_done(scsicmd);
2722− return 0;
3120+ memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3121+ sizeof(struct sense_data));
3122+ memset(&dev->fsa_dev[cid].sense_data, 0,
3123+ sizeof(struct sense_data));
3124+ scsicmd->result = AAC_STAT_GOOD;
3125+ break;
27233126
27243127 case ALLOW_MEDIUM_REMOVAL:
27253128 dprintk((KERN_DEBUG "LOCK command.\n"));
@@ -2728,9 +3131,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 2 unmodified lines
27283131 else
27293132 fsa_dev_ptr[cid].locked = 0;
27303133
2731− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2732− scsicmd->scsi_done(scsicmd);
2733− return 0;
3134+ scsicmd->result = AAC_STAT_GOOD;
3135+ break;
27343136 /*
27353137 * These commands are all No-Ops
27363138 */
@@ -2746,80 +3148,41 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd) · 9 unmodified lines
27463148 min_t(size_t,
27473149 sizeof(dev->fsa_dev[cid].sense_data),
27483150 SCSI_SENSE_BUFFERSIZE));
2749− scsicmd->scsi_done(scsicmd);
2750− return 0;
3151+ break;
27513152 }
2752− /* FALLTHRU */
27533153 case RESERVE:
27543154 case RELEASE:
27553155 case REZERO_UNIT:
27563156 case REASSIGN_BLOCKS:
27573157 case SEEK_10:
2758− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2759− scsicmd->scsi_done(scsicmd);
2760− return 0;
3158+ scsicmd->result = AAC_STAT_GOOD;
3159+ break;
27613160
27623161 case START_STOP:
27633162 return aac_start_stop(scsicmd);
2764− }
2765−
2766− switch (scsicmd->cmnd[0])
2767− {
2768− case READ_6:
2769− case READ_10:
2770− case READ_12:
2771− case READ_16:
2772− if (dev->in_reset)
2773− return -1;
2774− /*
2775− * Hack to keep track of ordinal number of the device that
2776− * corresponds to a container. Needed to convert
2777− * containers to /dev/sd device names
2778− */
2779−
2780− if (scsicmd->request->rq_disk)
2781− strlcpy(fsa_dev_ptr[cid].devname,
2782− scsicmd->request->rq_disk->disk_name,
2783− min(sizeof(fsa_dev_ptr[cid].devname),
2784− sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2785−
2786− return aac_read(scsicmd);
27873163
2788− case WRITE_6:
2789− case WRITE_10:
2790− case WRITE_12:
2791− case WRITE_16:
2792− if (dev->in_reset)
2793− return -1;
2794− return aac_write(scsicmd);
2795−
2796− case SYNCHRONIZE_CACHE:
2797− if (((aac_cache & 6) == 6) && dev->cache_protected) {
2798− scsicmd->result = DID_OK << 16 |
2799− COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2800− scsicmd->scsi_done(scsicmd);
2801− return 0;
2802− }
2803− /* Issue FIB to tell Firmware to flush it's cache */
2804− if ((aac_cache & 6) != 2)
2805− return aac_synchronize(scsicmd);
2806− /* FALLTHRU */
2807− default:
2808− /*
2809− * Unhandled commands
2810− */
2811− dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2812− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2813− set_sense(&dev->fsa_dev[cid].sense_data,
3164+ /* FALLTHRU */
3165+ default:
3166+ /*
3167+ * Unhandled commands
3168+ */
3169+ dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
3170+ scsicmd->cmnd[0]));
3171+ scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
3172+ SAM_STAT_CHECK_CONDITION;
3173+ set_sense(&dev->fsa_dev[cid].sense_data,
28143174 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
28153175 ASENCODE_INVALID_COMMAND, 0, 0);
2816− memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3176+ memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
28173177 min_t(size_t,
28183178 sizeof(dev->fsa_dev[cid].sense_data),
28193179 SCSI_SENSE_BUFFERSIZE));
2820− scsicmd->scsi_done(scsicmd);
2821− return 0;
28223180 }
3181+
3182+scsi_done_ret:
3183+
3184+ scsicmd->scsi_done(scsicmd);
3185+ return 0;
28233186 }
28243187
28253188 static int query_disk(struct aac_dev *dev, void __user *arg)
@@ -2954,16 +3317,11 @@ static void aac_srb_callback(void *context, struct fib * fibptr) · 128 unmodified lines
29543317 return;
29553318
29563319 BUG_ON(fibptr == NULL);
2957− dev = fibptr->dev;
29583320
2959− scsi_dma_unmap(scsicmd);
2960−
2961− /* expose physical device if expose_physicald flag is on */
2962− if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
2963− && expose_physicals > 0)
2964− aac_expose_phy_device(scsicmd);
3321+ dev = fibptr->dev;
29653322
29663323 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
3324+
29673325 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
29683326
29693327 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
@@ -2976,158 +3334,176 @@ static void aac_srb_callback(void *context, struct fib * fibptr) · 6 unmodified lines
29763334 */
29773335 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
29783336 - le32_to_cpu(srbreply->data_xfer_length));
2979− /*
2980− * First check the fib status
2981− */
3337+ }
29823338
2983− if (le32_to_cpu(srbreply->status) != ST_OK) {
2984− int len;
29853339
2986− printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2987− len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2988− SCSI_SENSE_BUFFERSIZE);
2989− scsicmd->result = DID_ERROR << 16
2990− | COMMAND_COMPLETE << 8
2991− | SAM_STAT_CHECK_CONDITION;
2992− memcpy(scsicmd->sense_buffer,
2993− srbreply->sense_data, len);
2994− }
3340+ scsi_dma_unmap(scsicmd);
29953341
2996− /*
2997− * Next check the srb status
2998− */
2999− switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3000− case SRB_STATUS_ERROR_RECOVERY:
3001− case SRB_STATUS_PENDING:
3002− case SRB_STATUS_SUCCESS:
3003− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3004− break;
3005− case SRB_STATUS_DATA_OVERRUN:
3006− switch (scsicmd->cmnd[0]) {
3007− case READ_6:
3008− case WRITE_6:
3009− case READ_10:
3010− case WRITE_10:
3011− case READ_12:
3012− case WRITE_12:
3013− case READ_16:
3014− case WRITE_16:
3015− if (le32_to_cpu(srbreply->data_xfer_length)
3016− < scsicmd->underflow)
3017− printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
3018− else
3019− printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
3020− scsicmd->result = DID_ERROR << 16
3021− | COMMAND_COMPLETE << 8;
3022− break;
3023− case INQUIRY: {
3024− scsicmd->result = DID_OK << 16
3025− | COMMAND_COMPLETE << 8;
3026− break;
3027− }
3028− default:
3029− scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3030− break;
3031− }
3032− break;
3033− case SRB_STATUS_ABORTED:
3034− scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3035− break;
3036− case SRB_STATUS_ABORT_FAILED:
3037− /*
3038− * Not sure about this one - but assuming the
3039− * hba was trying to abort for some reason
3040− */
3041− scsicmd->result = DID_ERROR << 16 | ABORT << 8;
3342+ /* expose physical device if expose_physicald flag is on */
3343+ if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
3344+ && expose_physicals > 0)
3345+ aac_expose_phy_device(scsicmd);
3346+
3347+ /*
3348+ * First check the fib status
3349+ */
3350+
3351+ if (le32_to_cpu(srbreply->status) != ST_OK) {
3352+ int len;
3353+
3354+ pr_warn("aac_srb_callback: srb failed, status = %d\n",
3355+ le32_to_cpu(srbreply->status));
3356+ len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3357+ SCSI_SENSE_BUFFERSIZE);
3358+ scsicmd->result = DID_ERROR << 16
3359+ | COMMAND_COMPLETE << 8
3360+ | SAM_STAT_CHECK_CONDITION;
3361+ memcpy(scsicmd->sense_buffer,
3362+ srbreply->sense_data, len);
3363+ }
3364+
3365+ /*
3366+ * Next check the srb status
3367+ */
3368+ switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3369+ case SRB_STATUS_ERROR_RECOVERY:
3370+ case SRB_STATUS_PENDING:
3371+ case SRB_STATUS_SUCCESS:
3372+ scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3373+ break;
3374+ case SRB_STATUS_DATA_OVERRUN:
3375+ switch (scsicmd->cmnd[0]) {
3376+ case READ_6:
3377+ case WRITE_6:
3378+ case READ_10:
3379+ case WRITE_10:
3380+ case READ_12:
3381+ case WRITE_12:
3382+ case READ_16:
3383+ case WRITE_16:
3384+ if (le32_to_cpu(srbreply->data_xfer_length)
3385+ < scsicmd->underflow)
3386+ pr_warn("aacraid: SCSI CMD underflow\n");
3387+ else
3388+ pr_warn("aacraid: SCSI CMD Data Overrun\n");
3389+ scsicmd->result = DID_ERROR << 16
3390+ | COMMAND_COMPLETE << 8;
30423391 break;
3043− case SRB_STATUS_PARITY_ERROR:
3044− scsicmd->result = DID_PARITY << 16
3045− | MSG_PARITY_ERROR << 8;
3392+ case INQUIRY:
3393+ scsicmd->result = DID_OK << 16
3394+ | COMMAND_COMPLETE << 8;
30463395 break;
3047− case SRB_STATUS_NO_DEVICE:
3048− case SRB_STATUS_INVALID_PATH_ID:
3049− case SRB_STATUS_INVALID_TARGET_ID:
3050− case SRB_STATUS_INVALID_LUN:
3051− case SRB_STATUS_SELECTION_TIMEOUT:
3052− scsicmd->result = DID_NO_CONNECT << 16
3053− | COMMAND_COMPLETE << 8;
3396+ default:
3397+ scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
30543398 break;
3399+ }
3400+ break;
3401+ case SRB_STATUS_ABORTED:
3402+ scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3403+ break;
3404+ case SRB_STATUS_ABORT_FAILED:
3405+ /*
3406+ * Not sure about this one - but assuming the
3407+ * hba was trying to abort for some reason
3408+ */
3409+ scsicmd->result = DID_ERROR << 16 | ABORT << 8;
3410+ break;
3411+ case SRB_STATUS_PARITY_ERROR:
3412+ scsicmd->result = DID_PARITY << 16
3413+ | MSG_PARITY_ERROR << 8;
3414+ break;
3415+ case SRB_STATUS_NO_DEVICE:
3416+ case SRB_STATUS_INVALID_PATH_ID:
3417+ case SRB_STATUS_INVALID_TARGET_ID:
3418+ case SRB_STATUS_INVALID_LUN:
3419+ case SRB_STATUS_SELECTION_TIMEOUT:
3420+ scsicmd->result = DID_NO_CONNECT << 16
3421+ | COMMAND_COMPLETE << 8;
3422+ break;
30553423
3056− case SRB_STATUS_COMMAND_TIMEOUT:
3057− case SRB_STATUS_TIMEOUT:
3058− scsicmd->result = DID_TIME_OUT << 16
3059− | COMMAND_COMPLETE << 8;
3060− break;
3424+ case SRB_STATUS_COMMAND_TIMEOUT:
3425+ case SRB_STATUS_TIMEOUT:
3426+ scsicmd->result = DID_TIME_OUT << 16
3427+ | COMMAND_COMPLETE << 8;
3428+ break;
30613429
3062− case SRB_STATUS_BUSY:
3063− scsicmd->result = DID_BUS_BUSY << 16
3064− | COMMAND_COMPLETE << 8;
3065− break;
3430+ case SRB_STATUS_BUSY:
3431+ scsicmd->result = DID_BUS_BUSY << 16
3432+ | COMMAND_COMPLETE << 8;
3433+ break;
30663434
3067− case SRB_STATUS_BUS_RESET:
3068− scsicmd->result = DID_RESET << 16
3069− | COMMAND_COMPLETE << 8;
3070− break;
3435+ case SRB_STATUS_BUS_RESET:
3436+ scsicmd->result = DID_RESET << 16
3437+ | COMMAND_COMPLETE << 8;
3438+ break;
30713439
3072− case SRB_STATUS_MESSAGE_REJECTED:
3073− scsicmd->result = DID_ERROR << 16
3074− | MESSAGE_REJECT << 8;
3075− break;
3076− case SRB_STATUS_REQUEST_FLUSHED:
3077− case SRB_STATUS_ERROR:
3078− case SRB_STATUS_INVALID_REQUEST:
3079− case SRB_STATUS_REQUEST_SENSE_FAILED:
3080− case SRB_STATUS_NO_HBA:
3081− case SRB_STATUS_UNEXPECTED_BUS_FREE:
3082− case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3083− case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3084− case SRB_STATUS_DELAYED_RETRY:
3085− case SRB_STATUS_BAD_FUNCTION:
3086− case SRB_STATUS_NOT_STARTED:
3087− case SRB_STATUS_NOT_IN_USE:
3088− case SRB_STATUS_FORCE_ABORT:
3089− case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3090− default:
3440+ case SRB_STATUS_MESSAGE_REJECTED:
3441+ scsicmd->result = DID_ERROR << 16
3442+ | MESSAGE_REJECT << 8;
3443+ break;
3444+ case SRB_STATUS_REQUEST_FLUSHED:
3445+ case SRB_STATUS_ERROR:
3446+ case SRB_STATUS_INVALID_REQUEST:
3447+ case SRB_STATUS_REQUEST_SENSE_FAILED:
3448+ case SRB_STATUS_NO_HBA:
3449+ case SRB_STATUS_UNEXPECTED_BUS_FREE:
3450+ case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3451+ case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3452+ case SRB_STATUS_DELAYED_RETRY:
3453+ case SRB_STATUS_BAD_FUNCTION:
3454+ case SRB_STATUS_NOT_STARTED:
3455+ case SRB_STATUS_NOT_IN_USE:
3456+ case SRB_STATUS_FORCE_ABORT:
3457+ case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3458+ default:
30913459 #ifdef AAC_DETAILED_STATUS_INFO
3092− printk(KERN_INFO "aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
3093− le32_to_cpu(srbreply->srb_status) & 0x3F,
3094− aac_get_status_string(
3095− le32_to_cpu(srbreply->srb_status) & 0x3F),
3096− scsicmd->cmnd[0],
3097− le32_to_cpu(srbreply->scsi_status));
3460+ pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3461+ le32_to_cpu(srbreply->srb_status) & 0x3F,
3462+ aac_get_status_string(
3463+ le32_to_cpu(srbreply->srb_status) & 0x3F),
3464+ scsicmd->cmnd[0],
3465+ le32_to_cpu(srbreply->scsi_status));
30983466 #endif
3099− if ((scsicmd->cmnd[0] == ATA_12)
3100− || (scsicmd->cmnd[0] == ATA_16)) {
3101− if (scsicmd->cmnd[2] & (0x01 << 5)) {
3102− scsicmd->result = DID_OK << 16
3103− | COMMAND_COMPLETE << 8;
3104− break;
3105− } else {
3106− scsicmd->result = DID_ERROR << 16
3107− | COMMAND_COMPLETE << 8;
3108− break;
3109− }
3467+ /*
3468+ * When the CC bit is SET by the host in ATA pass thru CDB,
3469+ * driver is supposed to return DID_OK
3470+ *
3471+ * When the CC bit is RESET by the host, driver should
3472+ * return DID_ERROR
3473+ */
3474+ if ((scsicmd->cmnd[0] == ATA_12)
3475+ || (scsicmd->cmnd[0] == ATA_16)) {
3476+
3477+ if (scsicmd->cmnd[2] & (0x01 << 5)) {
3478+ scsicmd->result = DID_OK << 16
3479+ | COMMAND_COMPLETE << 8;
3480+ break;
31103481 } else {
31113482 scsicmd->result = DID_ERROR << 16
31123483 | COMMAND_COMPLETE << 8;
3113− break;
3484+ break;
31143485 }
3486+ } else {
3487+ scsicmd->result = DID_ERROR << 16
3488+ | COMMAND_COMPLETE << 8;
3489+ break;
31153490 }
3116− if (le32_to_cpu(srbreply->scsi_status)
3117− == SAM_STAT_CHECK_CONDITION) {
3118− int len;
3491+ }
3492+ if (le32_to_cpu(srbreply->scsi_status)
3493+ == SAM_STAT_CHECK_CONDITION) {
3494+ int len;
31193495
3120− scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3121− len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3122− SCSI_SENSE_BUFFERSIZE);
3496+ scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3497+ len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3498+ SCSI_SENSE_BUFFERSIZE);
31233499 #ifdef AAC_DETAILED_STATUS_INFO
3124− printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
3125− le32_to_cpu(srbreply->status), len);
3500+ pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3501+ le32_to_cpu(srbreply->status), len);
31263502 #endif
3127− memcpy(scsicmd->sense_buffer,
3128− srbreply->sense_data, len);
3129− }
3503+ memcpy(scsicmd->sense_buffer,
3504+ srbreply->sense_data, len);
31303505 }
3506+
31313507 /*
31323508 * OR in the scsi status (already shifted up a bit)
31333509 */
@@ -3137,9 +3513,152 @@ static void aac_srb_callback(void *context, struct fib * fibptr) · 3 unmodified lines
31373513 scsicmd->scsi_done(scsicmd);
31383514 }
31393515
3516+static void hba_resp_task_complete(struct aac_dev *dev,
3517+ struct scsi_cmnd *scsicmd,
3518+ struct aac_hba_resp *err) {
3519+
3520+ scsicmd->result = err->status;
3521+ /* set residual count */
3522+ scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
3523+
3524+ switch (err->status) {
3525+ case SAM_STAT_GOOD:
3526+ scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3527+ break;
3528+ case SAM_STAT_CHECK_CONDITION:
3529+ {
3530+ int len;
3531+
3532+ len = min_t(u8, err->sense_response_data_len,
3533+ SCSI_SENSE_BUFFERSIZE);
3534+ if (len)
3535+ memcpy(scsicmd->sense_buffer,
3536+ err->sense_response_buf, len);
3537+ scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3538+ break;
3539+ }
3540+ case SAM_STAT_BUSY:
3541+ scsicmd->result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
3542+ break;
3543+ case SAM_STAT_TASK_ABORTED:
3544+ scsicmd->result |= DID_ABORT << 16 | ABORT << 8;
3545+ break;
3546+ case SAM_STAT_RESERVATION_CONFLICT:
3547+ case SAM_STAT_TASK_SET_FULL:
3548+ default:
3549+ scsicmd->result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3550+ break;
3551+ }
3552+}
3553+
3554+static void hba_resp_task_failure(struct aac_dev *dev,
3555+ struct scsi_cmnd *scsicmd,
3556+ struct aac_hba_resp *err)
3557+{
3558+ switch (err->status) {
3559+ case HBA_RESP_STAT_HBAMODE_DISABLED:
3560+ {
3561+ u32 bus, cid;
3562+
3563+ bus = aac_logical_to_phys(scmd_channel(scsicmd));
3564+ cid = scmd_id(scsicmd);
3565+ if (dev->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
3566+ dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
3567+ dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
3568+ }
3569+ scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3570+ break;
3571+ }
3572+ case HBA_RESP_STAT_IO_ERROR:
3573+ case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
3574+ scsicmd->result = DID_OK << 16 |
3575+ COMMAND_COMPLETE << 8 | SAM_STAT_BUSY;
3576+ break;
3577+ case HBA_RESP_STAT_IO_ABORTED:
3578+ scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3579+ break;
3580+ case HBA_RESP_STAT_INVALID_DEVICE:
3581+ scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3582+ break;
3583+ case HBA_RESP_STAT_UNDERRUN:
3584+ /* UNDERRUN is OK */
3585+ scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3586+ break;
3587+ case HBA_RESP_STAT_OVERRUN:
3588+ default:
3589+ scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3590+ break;
3591+ }
3592+}
3593+
3594+/**
3595+ *
3596+ * aac_hba_callback
3597+ * @context: the context set in the fib - here it is scsi cmd
3598+ * @fibptr: pointer to the fib
3599+ *
3600+ * Handles the completion of a native HBA scsi command
3601+ *
3602+ */
3603+void aac_hba_callback(void *context, struct fib *fibptr)
3604+{
3605+ struct aac_dev *dev;
3606+ struct scsi_cmnd *scsicmd;
3607+
3608+ struct aac_hba_resp *err =
3609+ &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
3610+
3611+ scsicmd = (struct scsi_cmnd *) context;
3612+
3613+ if (!aac_valid_context(scsicmd, fibptr))
3614+ return;
3615+
3616+ WARN_ON(fibptr == NULL);
3617+ dev = fibptr->dev;
3618+
3619+ if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF))
3620+ scsi_dma_unmap(scsicmd);
3621+
3622+ if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3623+ /* fast response */
3624+ scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3625+ goto out;
3626+ }
3627+
3628+ switch (err->service_response) {
3629+ case HBA_RESP_SVCRES_TASK_COMPLETE:
3630+ hba_resp_task_complete(dev, scsicmd, err);
3631+ break;
3632+ case HBA_RESP_SVCRES_FAILURE:
3633+ hba_resp_task_failure(dev, scsicmd, err);
3634+ break;
3635+ case HBA_RESP_SVCRES_TMF_REJECTED:
3636+ scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
3637+ break;
3638+ case HBA_RESP_SVCRES_TMF_LUN_INVALID:
3639+ scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3640+ break;
3641+ case HBA_RESP_SVCRES_TMF_COMPLETE:
3642+ case HBA_RESP_SVCRES_TMF_SUCCEEDED:
3643+ scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3644+ break;
3645+ default:
3646+ scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3647+ break;
3648+ }
3649+
3650+out:
3651+ aac_fib_complete(fibptr);
3652+
3653+ if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF)
3654+ scsicmd->SCp.sent_command = 1;
3655+ else
3656+ scsicmd->scsi_done(scsicmd);
3657+}
3658+
31403659 /**
31413660 *
3142− * aac_send_scb_fib
3661+ * aac_send_srb_fib
31433662 * @scsicmd: the scsi command block
31443663 *
31453664 * This routine will form a FIB and fill in the aac_srb from the
@@ -3182,6 +3701,54 @@ static int aac_send_srb_fib(struct scsi_cmnd* scsicmd) · 36 unmodified lines
31823701 return -1;
31833702 }
31843703
3704+/**
3705+ *
3706+ * aac_send_hba_fib
3707+ * @scsicmd: the scsi command block
3708+ *
3709+ * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3710+ * scsicmd passed in.
3711+ */
3712+static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
3713+{
3714+ struct fib *cmd_fibcontext;
3715+ struct aac_dev *dev;
3716+ int status;
3717+
3718+ dev = shost_priv(scsicmd->device->host);
3719+ if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3720+ scsicmd->device->lun > AAC_MAX_LUN - 1) {
3721+ scsicmd->result = DID_NO_CONNECT << 16;
3722+ scsicmd->scsi_done(scsicmd);
3723+ return 0;
3724+ }
3725+
3726+ /*
3727+ * Allocate and initialize a Fib then setup a BlockWrite command
3728+ */
3729+ cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3730+ if (!cmd_fibcontext)
3731+ return -1;
3732+
3733+ status = aac_adapter_hba(cmd_fibcontext, scsicmd);
3734+
3735+ /*
3736+ * Check that the command queued to the controller
3737+ */
3738+ if (status == -EINPROGRESS) {
3739+ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3740+ return 0;
3741+ }
3742+
3743+ pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3744+ status);
3745+ aac_fib_complete(cmd_fibcontext);
3746+ aac_fib_free(cmd_fibcontext);
3747+
3748+ return -1;
3749+}
3750+
3751+
31853752 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
31863753 {
31873754 struct aac_dev *dev;
@@ -3434,6 +4001,75 @@ static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int · 246 unmodified lines
34344001 return 0;
34354002 }
34364003
4004+static long aac_build_sghba(struct scsi_cmnd *scsicmd,
4005+ struct aac_hba_cmd_req *hbacmd,
4006+ int sg_max,
4007+ u64 sg_address)
4008+{
4009+ unsigned long byte_count = 0;
4010+ int nseg;
4011+ struct scatterlist *sg;
4012+ int i;
4013+ u32 cur_size;
4014+ struct aac_hba_sgl *sge;
4015+
4016+ nseg = scsi_dma_map(scsicmd);
4017+ if (nseg <= 0) {
4018+ byte_count = nseg;
4019+ goto out;
4020+ }
4021+
4022+ if (nseg > HBA_MAX_SG_EMBEDDED)
4023+ sge = &hbacmd->sge[2];
4024+ else
4025+ sge = &hbacmd->sge[0];
4026+
4027+ scsi_for_each_sg(scsicmd, sg, nseg, i) {
4028+ int count = sg_dma_len(sg);
4029+ u64 addr = sg_dma_address(sg);
4030+
4031+ WARN_ON(i >= sg_max);
4032+ sge->addr_hi = cpu_to_le32((u32)(addr>>32));
4033+ sge->addr_lo = cpu_to_le32((u32)(addr & 0xffffffff));
4034+ cur_size = cpu_to_le32(count);
4035+ sge->len = cur_size;
4036+ sge->flags = 0;
4037+ byte_count += count;
4038+ sge++;
4039+ }
4040+
4041+ sge--;
4042+ /* hba wants the size to be exact */
4043+ if (byte_count > scsi_bufflen(scsicmd)) {
4044+ u32 temp;
4045+
4046+ temp = le32_to_cpu(sge->len) - byte_count
4047+ - scsi_bufflen(scsicmd);
4048+ sge->len = cpu_to_le32(temp);
4049+ byte_count = scsi_bufflen(scsicmd);
4050+ }
4051+
4052+ if (nseg <= HBA_MAX_SG_EMBEDDED) {
4053+ hbacmd->emb_data_desc_count = cpu_to_le32(nseg);
4054+ sge->flags = cpu_to_le32(0x40000000);
4055+ } else {
4056+ /* not embedded */
4057+ hbacmd->sge[0].flags = cpu_to_le32(0x80000000);
4058+ hbacmd->emb_data_desc_count = (u8)cpu_to_le32(1);
4059+ hbacmd->sge[0].addr_hi = (u32)cpu_to_le32(sg_address >> 32);
4060+ hbacmd->sge[0].addr_lo =
4061+ cpu_to_le32((u32)(sg_address & 0xffffffff));
4062+ }
4063+
4064+ /* Check for command underflow */
4065+ if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4066+ pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4067+ byte_count, scsicmd->underflow);
4068+ }
4069+out:
4070+ return byte_count;
4071+}
4072+
34374073 #ifdef AAC_DETAILED_STATUS_INFO
34384074
34394075 struct aac_srb_status_info {
drivers/scsi/aacraid/aacraid.h+568−76
@@ -1,3 +1,37 @@
1+/*
2+ * Adaptec AAC series RAID controller driver
3+ * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
4+ *
5+ * based on the old aacraid driver that is..
6+ * Adaptec aacraid device driver for Linux.
7+ *
8+ * Copyright (c) 2000-2010 Adaptec, Inc.
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
11+ *
12+ * This program is free software; you can redistribute it and/or modify
13+ * it under the terms of the GNU General Public License as published by
14+ * the Free Software Foundation; either version 2, or (at your option)
15+ * any later version.
16+ *
17+ * This program is distributed in the hope that it will be useful,
18+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+ * GNU General Public License for more details.
21+ *
22+ * You should have received a copy of the GNU General Public License
23+ * along with this program; see the file COPYING. If not, write to
24+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25+ *
26+ * Module Name:
27+ * aacraid.h
28+ *
29+ * Abstract: Contains all routines for control of the aacraid driver
30+ *
31+ */
32+
33+#ifndef _AACRAID_H_
34+#define _AACRAID_H_
135 #ifndef dprintk
236 # define dprintk(x)
337 #endif
@@ -63,8 +97,8 @@ enum { · 59 unmodified lines
6397 #define PMC_GLOBAL_INT_BIT0 0x00000001
6498
6599 #ifndef AAC_DRIVER_BUILD
66−# define AAC_DRIVER_BUILD 41066
67−# define AAC_DRIVER_BRANCH "-ms"
100+# define AAC_DRIVER_BUILD 50740
101+# define AAC_DRIVER_BRANCH "-custom"
68102 #endif
69103 #define MAXIMUM_NUM_CONTAINERS 32
70104
@@ -72,13 +106,311 @@ enum { · 1 unmodified line
72106 #define AAC_NUM_IO_FIB (1024 - AAC_NUM_MGT_FIB)
73107 #define AAC_NUM_FIB (AAC_NUM_IO_FIB + AAC_NUM_MGT_FIB)
74108
75−#define AAC_MAX_LUN (8)
109+#define AAC_MAX_LUN 256
76110
77111 #define AAC_MAX_HOSTPHYSMEMPAGES (0xfffff)
78112 #define AAC_MAX_32BIT_SGBCOUNT ((unsigned short)256)
79113
80114 #define AAC_DEBUG_INSTRUMENT_AIF_DELETE
81115
116+#define AAC_MAX_NATIVE_TARGETS 1024
117+/* Thor: 5 phys. buses: #0: empty, 1-4: 256 targets each */
118+#define AAC_MAX_BUSES 5
119+#define AAC_MAX_TARGETS 256
120+#define AAC_MAX_NATIVE_SIZE 2048
121+#define FW_ERROR_BUFFER_SIZE 512
122+
123+/* Thor AIF events */
124+#define SA_AIF_HOTPLUG (1<<1)
125+#define SA_AIF_HARDWARE (1<<2)
126+#define SA_AIF_PDEV_CHANGE (1<<4)
127+#define SA_AIF_LDEV_CHANGE (1<<5)
128+#define SA_AIF_BPSTAT_CHANGE (1<<30)
129+#define SA_AIF_BPCFG_CHANGE (1<<31)
130+
131+#define HBA_MAX_SG_EMBEDDED 28
132+#define HBA_MAX_SG_SEPARATE 90
133+#define HBA_SENSE_DATA_LEN_MAX 32
134+#define HBA_REQUEST_TAG_ERROR_FLAG 0x00000002
135+#define HBA_SGL_FLAGS_EXT 0x80000000UL
136+
137+struct aac_hba_sgl {
138+ u32 addr_lo; /* Lower 32-bits of SGL element address */
139+ u32 addr_hi; /* Upper 32-bits of SGL element address */
140+ u32 len; /* Length of SGL element in bytes */
141+ u32 flags; /* SGL element flags */
142+};
143+
144+enum {
145+ HBA_IU_TYPE_SCSI_CMD_REQ = 0x40,
146+ HBA_IU_TYPE_SCSI_TM_REQ = 0x41,
147+ HBA_IU_TYPE_SATA_REQ = 0x42,
148+ HBA_IU_TYPE_RESP = 0x60,
149+ HBA_IU_TYPE_COALESCED_RESP = 0x61,
150+ HBA_IU_TYPE_INT_COALESCING_CFG_REQ = 0x70
151+};
152+
153+enum {
154+ HBA_CMD_BYTE1_DATA_DIR_IN = 0x1,
155+ HBA_CMD_BYTE1_DATA_DIR_OUT = 0x2,
156+ HBA_CMD_BYTE1_DATA_TYPE_DDR = 0x4,
157+ HBA_CMD_BYTE1_CRYPTO_ENABLE = 0x8
158+};
159+
160+enum {
161+ HBA_CMD_BYTE1_BITOFF_DATA_DIR_IN = 0x0,
162+ HBA_CMD_BYTE1_BITOFF_DATA_DIR_OUT,
163+ HBA_CMD_BYTE1_BITOFF_DATA_TYPE_DDR,
164+ HBA_CMD_BYTE1_BITOFF_CRYPTO_ENABLE
165+};
166+
167+enum {
168+ HBA_RESP_DATAPRES_NO_DATA = 0x0,
169+ HBA_RESP_DATAPRES_RESPONSE_DATA,
170+ HBA_RESP_DATAPRES_SENSE_DATA
171+};
172+
173+enum {
174+ HBA_RESP_SVCRES_TASK_COMPLETE = 0x0,
175+ HBA_RESP_SVCRES_FAILURE,
176+ HBA_RESP_SVCRES_TMF_COMPLETE,
177+ HBA_RESP_SVCRES_TMF_SUCCEEDED,
178+ HBA_RESP_SVCRES_TMF_REJECTED,
179+ HBA_RESP_SVCRES_TMF_LUN_INVALID
180+};
181+
182+enum {
183+ HBA_RESP_STAT_IO_ERROR = 0x1,
184+ HBA_RESP_STAT_IO_ABORTED,
185+ HBA_RESP_STAT_NO_PATH_TO_DEVICE,
186+ HBA_RESP_STAT_INVALID_DEVICE,
187+ HBA_RESP_STAT_HBAMODE_DISABLED = 0xE,
188+ HBA_RESP_STAT_UNDERRUN = 0x51,
189+ HBA_RESP_STAT_OVERRUN = 0x75
190+};
191+
192+struct aac_hba_cmd_req {
193+ u8 iu_type; /* HBA information unit type */
194+ /*
195+ * byte1:
196+ * [1:0] DIR - 0=No data, 0x1 = IN, 0x2 = OUT
197+ * [2] TYPE - 0=PCI, 1=DDR
198+ * [3] CRYPTO_ENABLE - 0=Crypto disabled, 1=Crypto enabled
199+ */
200+ u8 byte1;
201+ u8 reply_qid; /* Host reply queue to post response to */
202+ u8 reserved1;
203+ __le32 it_nexus; /* Device handle for the request */
204+ __le32 request_id; /* Sender context */
205+ /* Lower 32-bits of tweak value for crypto enabled IOs */
206+ __le32 tweak_value_lo;
207+ u8 cdb[16]; /* SCSI CDB of the command */
208+ u8 lun[8]; /* SCSI LUN of the command */
209+
210+ /* Total data length in bytes to be read/written (if any) */
211+ __le32 data_length;
212+
213+ /* [2:0] Task Attribute, [6:3] Command Priority */
214+ u8 attr_prio;
215+
216+ /* Number of SGL elements embedded in the HBA req */
217+ u8 emb_data_desc_count;
218+
219+ __le16 dek_index; /* DEK index for crypto enabled IOs */
220+
221+ /* Lower 32-bits of reserved error data target location on the host */
222+ __le32 error_ptr_lo;
223+
224+ /* Upper 32-bits of reserved error data target location on the host */
225+ __le32 error_ptr_hi;
226+
227+ /* Length of reserved error data area on the host in bytes */
228+ __le32 error_length;
229+
230+ /* Upper 32-bits of tweak value for crypto enabled IOs */
231+ __le32 tweak_value_hi;
232+
233+ struct aac_hba_sgl sge[HBA_MAX_SG_SEPARATE+2]; /* SG list space */
234+
235+ /*
236+ * structure must not exceed
237+ * AAC_MAX_NATIVE_SIZE-FW_ERROR_BUFFER_SIZE
238+ */
239+};
240+
241+/* Task Management Functions (TMF) */
242+#define HBA_TMF_ABORT_TASK 0x01
243+#define HBA_TMF_LUN_RESET 0x08
244+
245+struct aac_hba_tm_req {
246+ u8 iu_type; /* HBA information unit type */
247+ u8 reply_qid; /* Host reply queue to post response to */
248+ u8 tmf; /* Task management function */
249+ u8 reserved1;
250+
251+ __le32 it_nexus; /* Device handle for the command */
252+
253+ u8 lun[8]; /* SCSI LUN */
254+
255+ /* Used to hold sender context. */
256+ __le32 request_id; /* Sender context */
257+ __le32 reserved2;
258+
259+ /* Request identifier of managed task */
260+ __le32 managed_request_id; /* Sender context being managed */
261+ __le32 reserved3;
262+
263+ /* Lower 32-bits of reserved error data target location on the host */
264+ __le32 error_ptr_lo;
265+ /* Upper 32-bits of reserved error data target location on the host */
266+ __le32 error_ptr_hi;
267+ /* Length of reserved error data area on the host in bytes */
268+ __le32 error_length;
269+};
270+
271+struct aac_hba_reset_req {
272+ u8 iu_type; /* HBA information unit type */
273+ /* 0 - reset specified device, 1 - reset all devices */
274+ u8 reset_type;
275+ u8 reply_qid; /* Host reply queue to post response to */
276+ u8 reserved1;
277+
278+ __le32 it_nexus; /* Device handle for the command */
279+ __le32 request_id; /* Sender context */
280+ /* Lower 32-bits of reserved error data target location on the host */
281+ __le32 error_ptr_lo;
282+ /* Upper 32-bits of reserved error data target location on the host */
283+ __le32 error_ptr_hi;
284+ /* Length of reserved error data area on the host in bytes */
285+ __le32 error_length;
286+};
287+
288+struct aac_hba_resp {
289+ u8 iu_type; /* HBA information unit type */
290+ u8 reserved1[3];
291+ __le32 request_identifier; /* sender context */
292+ __le32 reserved2;
293+ u8 service_response; /* SCSI service response */
294+ u8 status; /* SCSI status */
295+ u8 datapres; /* [1:0] - data present, [7:2] - reserved */
296+ u8 sense_response_data_len; /* Sense/response data length */
297+ __le32 residual_count; /* Residual data length in bytes */
298+ /* Sense/response data */
299+ u8 sense_response_buf[HBA_SENSE_DATA_LEN_MAX];
300+};
301+
302+struct aac_native_hba {
303+ union {
304+ struct aac_hba_cmd_req cmd;
305+ struct aac_hba_tm_req tmr;
306+ u8 cmd_bytes[AAC_MAX_NATIVE_SIZE-FW_ERROR_BUFFER_SIZE];
307+ } cmd;
308+ union {
309+ struct aac_hba_resp err;
310+ u8 resp_bytes[FW_ERROR_BUFFER_SIZE];
311+ } resp;
312+};
313+
314+#define CISS_REPORT_PHYSICAL_LUNS 0xc3
315+#define WRITE_HOST_WELLNESS 0xa5
316+#define CISS_IDENTIFY_PHYSICAL_DEVICE 0x15
317+#define BMIC_IN 0x26
318+#define BMIC_OUT 0x27
319+
320+struct aac_ciss_phys_luns_resp {
321+ u8 list_length[4]; /* LUN list length (N-7, big endian) */
322+ u8 resp_flag; /* extended response_flag */
323+ u8 reserved[3];
324+ struct _ciss_lun {
325+ u8 tid[3]; /* Target ID */
326+ u8 bus; /* Bus, flag (bits 6,7) */
327+ u8 level3[2];
328+ u8 level2[2];
329+ u8 node_ident[16]; /* phys. node identifier */
330+ } lun[1]; /* List of phys. devices */
331+};
332+
333+/*
334+ * Interrupts
335+ */
336+#define AAC_MAX_HRRQ 64
337+
338+struct aac_ciss_identify_pd {
339+ u8 scsi_bus; /* SCSI Bus number on controller */
340+ u8 scsi_id; /* SCSI ID on this bus */
341+ u16 block_size; /* sector size in bytes */
342+ u32 total_blocks; /* number for sectors on drive */
343+ u32 reserved_blocks; /* controller reserved (RIS) */
344+ u8 model[40]; /* Physical Drive Model */
345+ u8 serial_number[40]; /* Drive Serial Number */
346+ u8 firmware_revision[8]; /* drive firmware revision */
347+ u8 scsi_inquiry_bits; /* inquiry byte 7 bits */
348+ u8 compaq_drive_stamp; /* 0 means drive not stamped */
349+ u8 last_failure_reason;
350+
351+ u8 flags;
352+ u8 more_flags;
353+ u8 scsi_lun; /* SCSI LUN for phys drive */
354+ u8 yet_more_flags;
355+ u8 even_more_flags;
356+ u32 spi_speed_rules; /* SPI Speed :Ultra disable diagnose */
357+ u8 phys_connector[2]; /* connector number on controller */
358+ u8 phys_box_on_bus; /* phys enclosure this drive resides */
359+ u8 phys_bay_in_box; /* phys drv bay this drive resides */
360+ u32 rpm; /* Drive rotational speed in rpm */
361+ u8 device_type; /* type of drive */
362+ u8 sata_version; /* only valid when drive_type is SATA */
363+ u64 big_total_block_count;
364+ u64 ris_starting_lba;
365+ u32 ris_size;
366+ u8 wwid[20];
367+ u8 controller_phy_map[32];
368+ u16 phy_count;
369+ u8 phy_connected_dev_type[256];
370+ u8 phy_to_drive_bay_num[256];
371+ u16 phy_to_attached_dev_index[256];
372+ u8 box_index;
373+ u8 spitfire_support;
374+ u16 extra_physical_drive_flags;
375+ u8 negotiated_link_rate[256];
376+ u8 phy_to_phy_map[256];
377+ u8 redundant_path_present_map;
378+ u8 redundant_path_failure_map;
379+ u8 active_path_number;
380+ u16 alternate_paths_phys_connector[8];
381+ u8 alternate_paths_phys_box_on_port[8];
382+ u8 multi_lun_device_lun_count;
383+ u8 minimum_good_fw_revision[8];
384+ u8 unique_inquiry_bytes[20];
385+ u8 current_temperature_degreesC;
386+ u8 temperature_threshold_degreesC;
387+ u8 max_temperature_degreesC;
388+ u8 logical_blocks_per_phys_block_exp; /* phyblocksize = 512 * 2^exp */
389+ u16 current_queue_depth_limit;
390+ u8 switch_name[10];
391+ u16 switch_port;
392+ u8 alternate_paths_switch_name[40];
393+ u8 alternate_paths_switch_port[8];
394+ u16 power_on_hours; /* valid only if gas gauge supported */
395+ u16 percent_endurance_used; /* valid only if gas gauge supported. */
396+ u8 drive_authentication;
397+ u8 smart_carrier_authentication;
398+ u8 smart_carrier_app_fw_version;
399+ u8 smart_carrier_bootloader_fw_version;
400+ u8 SanitizeSecureEraseSupport;
401+ u8 DriveKeyFlags;
402+ u8 encryption_key_name[64];
403+ u32 misc_drive_flags;
404+ u16 dek_index;
405+ u16 drive_encryption_flags;
406+ u8 sanitize_maximum_time[6];
407+ u8 connector_info_mode;
408+ u8 connector_info_number[4];
409+ u8 long_connector_name[64];
410+ u8 device_unique_identifier[16];
411+ u8 padto_2K[17];
412+} __packed;
413+
82414 /*
83415 * These macros convert from physical channels to virtual channels
84416 */
@@ -86,6 +418,7 @@ enum { · 1 unmodified line
86418 #define CONTAINER_TO_CHANNEL(cont) (CONTAINER_CHANNEL)
87419 #define CONTAINER_TO_ID(cont) (cont)
88420 #define CONTAINER_TO_LUN(cont) (0)
421+#define ENCLOSURE_CHANNEL (3)
89422
90423 #define PMC_DEVICE_S6 0x28b
91424 #define PMC_DEVICE_S7 0x28c
@@ -351,10 +684,10 @@ enum aac_queue_types { · 259 unmodified lines
351684
352685 /* transport FIB header (PMC) */
353686 struct aac_fib_xporthdr {
354− u64 HostAddress; /* FIB host address w/o xport header */
355− u32 Size; /* FIB size excluding xport header */
356− u32 Handle; /* driver handle to reference the FIB */
357− u64 Reserved[2];
687+ __le64 HostAddress; /* FIB host address w/o xport header */
688+ __le32 Size; /* FIB size excluding xport header */
689+ __le32 Handle; /* driver handle to reference the FIB */
690+ __le64 Reserved[2];
358691 };
359692
360693 #define ALIGN32 32
@@ -379,7 +712,7 @@ struct aac_fibhdr { · 18 unmodified lines
379712 __le32 SenderFibAddressHigh;/* upper 32bit of phys. FIB address */
380713 __le32 TimeStamp; /* otherwise timestamp for FW internal use */
381714 } u;
382− u32 Handle; /* FIB handle used for MSGU commnunication */
715+ __le32 Handle; /* FIB handle used for MSGU commnunication */
383716 u32 Previous; /* FW internal use */
384717 u32 Next; /* FW internal use */
385718 };
@@ -489,41 +822,64 @@ enum fib_xfer_state { · 103 unmodified lines
489822 #define ADAPTER_INIT_STRUCT_REVISION_4 4 // rocket science
490823 #define ADAPTER_INIT_STRUCT_REVISION_6 6 /* PMC src */
491824 #define ADAPTER_INIT_STRUCT_REVISION_7 7 /* Denali */
825+#define ADAPTER_INIT_STRUCT_REVISION_8 8 // Thor
492826
493−struct aac_init
827+union aac_init
494828 {
495− __le32 InitStructRevision;
496− __le32 Sa_MSIXVectors;
497− __le32 fsrev;
498− __le32 CommHeaderAddress;
499− __le32 FastIoCommAreaAddress;
500− __le32 AdapterFibsPhysicalAddress;
501− __le32 AdapterFibsVirtualAddress;
502− __le32 AdapterFibsSize;
503− __le32 AdapterFibAlign;
504− __le32 printfbuf;
505− __le32 printfbufsiz;
506− __le32 HostPhysMemPages; /* number of 4k pages of host
507− physical memory */
508− __le32 HostElapsedSeconds; /* number of seconds since 1970. */
509− /*
510− * ADAPTER_INIT_STRUCT_REVISION_4 begins here
511− */
512− __le32 InitFlags; /* flags for supported features */
829+ struct _r7 {
830+ __le32 init_struct_revision;
831+ __le32 no_of_msix_vectors;
832+ __le32 fsrev;
833+ __le32 comm_header_address;
834+ __le32 fast_io_comm_area_address;
835+ __le32 adapter_fibs_physical_address;
836+ __le32 adapter_fibs_virtual_address;
837+ __le32 adapter_fibs_size;
838+ __le32 adapter_fib_align;
839+ __le32 printfbuf;
840+ __le32 printfbufsiz;
841+ /* number of 4k pages of host phys. mem. */
842+ __le32 host_phys_mem_pages;
843+ /* number of seconds since 1970. */
844+ __le32 host_elapsed_seconds;
845+ /* ADAPTER_INIT_STRUCT_REVISION_4 begins here */
846+ __le32 init_flags; /* flags for supported features */
513847 #define INITFLAGS_NEW_COMM_SUPPORTED 0x00000001
514848 #define INITFLAGS_DRIVER_USES_UTC_TIME 0x00000010
515849 #define INITFLAGS_DRIVER_SUPPORTS_PM 0x00000020
516850 #define INITFLAGS_NEW_COMM_TYPE1_SUPPORTED 0x00000040
517851 #define INITFLAGS_FAST_JBOD_SUPPORTED 0x00000080
518852 #define INITFLAGS_NEW_COMM_TYPE2_SUPPORTED 0x00000100
519− __le32 MaxIoCommands; /* max outstanding commands */
520− __le32 MaxIoSize; /* largest I/O command */
521− __le32 MaxFibSize; /* largest FIB to adapter */
522− /* ADAPTER_INIT_STRUCT_REVISION_5 begins here */
523− __le32 MaxNumAif; /* max number of aif */
524− /* ADAPTER_INIT_STRUCT_REVISION_6 begins here */
525− __le32 HostRRQ_AddrLow;
526− __le32 HostRRQ_AddrHigh; /* Host RRQ (response queue) for SRC */
853+#define INITFLAGS_DRIVER_SUPPORTS_HBA_MODE 0x00000400
854+ __le32 max_io_commands; /* max outstanding commands */
855+ __le32 max_io_size; /* largest I/O command */
856+ __le32 max_fib_size; /* largest FIB to adapter */
857+ /* ADAPTER_INIT_STRUCT_REVISION_5 begins here */
858+ __le32 max_num_aif; /* max number of aif */
859+ /* ADAPTER_INIT_STRUCT_REVISION_6 begins here */
860+ /* Host RRQ (response queue) for SRC */
861+ __le32 host_rrq_addr_low;
862+ __le32 host_rrq_addr_high;
863+ } r7;
864+ struct _r8 {
865+ /* ADAPTER_INIT_STRUCT_REVISION_8 */
866+ __le32 init_struct_revision;
867+ __le32 rr_queue_count;
868+ __le32 host_elapsed_seconds; /* number of secs since 1970. */
869+ __le32 init_flags;
870+ __le32 max_io_size; /* largest I/O command */
871+ __le32 max_num_aif; /* max number of aif */
872+ __le32 reserved1;
873+ __le32 reserved2;
874+ struct _rrq {
875+ __le32 host_addr_low;
876+ __le32 host_addr_high;
877+ __le16 msix_id;
878+ __le16 element_count;
879+ __le16 comp_thresh;
880+ __le16 unused;
881+ } rrq[1]; /* up to 64 RRQ addresses */
882+ } r8;
527883 };
528884
529885 enum aac_log_level {
@@ -554,7 +910,7 @@ struct adapter_ops · 24 unmodified lines
554910 void (*adapter_enable_int)(struct aac_dev *dev);
555911 int (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4);
556912 int (*adapter_check_health)(struct aac_dev *dev);
557− int (*adapter_restart)(struct aac_dev *dev, int bled);
913+ int (*adapter_restart)(struct aac_dev *dev, int bled, u8 reset_type);
558914 void (*adapter_start)(struct aac_dev *dev);
559915 /* Transport operations */
560916 int (*adapter_ioremap)(struct aac_dev * dev, u32 size);
@@ -727,6 +1083,7 @@ struct sa_registers { · 166 unmodified lines
7271083
7281084
7291085 #define SA_INIT_NUM_MSIXVECTORS 1
1086+#define SA_MINIPORT_REVISION SA_INIT_NUM_MSIXVECTORS
7301087
7311088 #define sa_readw(AEP, CSR) readl(&((AEP)->regs.sa->CSR))
7321089 #define sa_readl(AEP, CSR) readl(&((AEP)->regs.sa->CSR))
@@ -820,32 +1177,37 @@ struct rkt_registers { · 87 unmodified lines
8201177 #define src_inbound rx_inbound
8211178
8221179 struct src_mu_registers {
823− /* PCI*| Name */
824− __le32 reserved0[6]; /* 00h | Reserved */
825− __le32 IOAR[2]; /* 18h | IOA->host interrupt register */
826− __le32 IDR; /* 20h | Inbound Doorbell Register */
827− __le32 IISR; /* 24h | Inbound Int. Status Register */
828− __le32 reserved1[3]; /* 28h | Reserved */
829− __le32 OIMR; /* 34h | Outbound Int. Mask Register */
830− __le32 reserved2[25]; /* 38h | Reserved */
831− __le32 ODR_R; /* 9ch | Outbound Doorbell Read */
832− __le32 ODR_C; /* a0h | Outbound Doorbell Clear */
833− __le32 reserved3[6]; /* a4h | Reserved */
834− __le32 OMR; /* bch | Outbound Message Register */
1180+ /* PCI*| Name */
1181+ __le32 reserved0[6]; /* 00h | Reserved */
1182+ __le32 IOAR[2]; /* 18h | IOA->host interrupt register */
1183+ __le32 IDR; /* 20h | Inbound Doorbell Register */
1184+ __le32 IISR; /* 24h | Inbound Int. Status Register */
1185+ __le32 reserved1[3]; /* 28h | Reserved */
1186+ __le32 OIMR; /* 34h | Outbound Int. Mask Register */
1187+ __le32 reserved2[25]; /* 38h | Reserved */
1188+ __le32 ODR_R; /* 9ch | Outbound Doorbell Read */
1189+ __le32 ODR_C; /* a0h | Outbound Doorbell Clear */
1190+ __le32 reserved3[3]; /* a4h | Reserved */
1191+ __le32 SCR0; /* b0h | Scratchpad 0 */
1192+ __le32 reserved4[2]; /* b4h | Reserved */
1193+ __le32 OMR; /* bch | Outbound Message Register */
8351194 __le32 IQ_L; /* c0h | Inbound Queue (Low address) */
8361195 __le32 IQ_H; /* c4h | Inbound Queue (High address) */
8371196 __le32 ODR_MSI; /* c8h | MSI register for sync./AIF */
1197+ __le32 reserved5; /* cch | Reserved */
1198+ __le32 IQN_L; /* d0h | Inbound (native cmd) low */
1199+ __le32 IQN_H; /* d4h | Inbound (native cmd) high */
8381200 };
8391201
8401202 struct src_registers {
8411203 struct src_mu_registers MUnit; /* 00h - cbh */
8421204 union {
8431205 struct {
844− __le32 reserved1[130789]; /* cch - 7fc5fh */
1206+ __le32 reserved1[130786]; /* d8h - 7fc5fh */
8451207 struct src_inbound IndexRegs; /* 7fc60h */
8461208 } tupelo;
8471209 struct {
848− __le32 reserved1[973]; /* cch - fffh */
1210+ __le32 reserved1[970]; /* d8h - fffh */
8491211 struct src_inbound IndexRegs; /* 1000h */
8501212 } denali;
8511213 } u;
@@ -930,6 +1292,7 @@ struct fsa_dev_info { · 78 unmodified lines
9301292 char devname[8];
9311293 struct sense_data sense_data;
9321294 u32 block_size;
1295+ u8 identifier[16];
9331296 };
9341297
9351298 struct fib {
@@ -958,8 +1321,30 @@ struct fib { · 22 unmodified lines
9581321 struct list_head fiblink;
9591322 void *data;
9601323 u32 vector_no;
961− struct hw_fib *hw_fib_va; /* Actual shared object */
962− dma_addr_t hw_fib_pa; /* physical address of hw_fib*/
1324+ struct hw_fib *hw_fib_va; /* also used for native */
1325+ dma_addr_t hw_fib_pa; /* physical address of hw_fib*/
1326+ dma_addr_t hw_sgl_pa; /* extra sgl for native */
1327+ dma_addr_t hw_error_pa; /* error buffer for native */
1328+ u32 hbacmd_size; /* cmd size for native */
1329+};
1330+
1331+#define AAC_INIT 0
1332+#define AAC_RESCAN 1
1333+
1334+#define AAC_DEVTYPE_RAID_MEMBER 1
1335+#define AAC_DEVTYPE_ARC_RAW 2
1336+#define AAC_DEVTYPE_NATIVE_RAW 3
1337+#define AAC_EXPOSE_DISK 0
1338+#define AAC_HIDE_DISK 3
1339+
1340+struct aac_hba_map_info {
1341+ __le32 rmw_nexus; /* nexus for native HBA devices */
1342+ u8 devtype; /* device type */
1343+ u8 new_devtype;
1344+ u8 reset_state; /* 0 - no reset, 1..x - */
1345+ /* after xth TM LUN reset */
1346+ u16 qd_limit;
1347+ u8 expose; /*checks if to expose or not*/
9631348 };
9641349
9651350 /*
@@ -1025,7 +1410,28 @@ struct aac_supplement_adapter_info · 59 unmodified lines
10251410 /* StructExpansion == 1 */
10261411 __le32 FeatureBits3;
10271412 __le32 SupportedPerformanceModes;
1028− __le32 ReservedForFutureGrowth[80];
1413+ u8 HostBusType; /* uses HOST_BUS_TYPE_xxx defines */
1414+ u8 HostBusWidth; /* actual width in bits or links */
1415+ u16 HostBusSpeed; /* actual bus speed/link rate in MHz */
1416+ u8 MaxRRCDrives; /* max. number of ITP-RRC drives/pool */
1417+ u8 MaxDiskXtasks; /* max. possible num of DiskX Tasks */
1418+
1419+ u8 CpldVerLoaded;
1420+ u8 CpldVerInFlash;
1421+
1422+ __le64 MaxRRCCapacity;
1423+ __le32 CompiledMaxHistLogLevel;
1424+ u8 CustomBoardName[12];
1425+ u16 SupportedCntlrMode; /* identify supported controller mode */
1426+ u16 ReservedForFuture16;
1427+ __le32 SupportedOptions3; /* reserved for future options */
1428+
1429+ __le16 VirtDeviceBus; /* virt. SCSI device for Thor */
1430+ __le16 VirtDeviceTarget;
1431+ __le16 VirtDeviceLUN;
1432+ __le16 Unused;
1433+ __le32 ReservedForFutureGrowth[68];
1434+
10291435 };
10301436 #define AAC_FEATURE_FALCON cpu_to_le32(0x00000010)
10311437 #define AAC_FEATURE_JBOD cpu_to_le32(0x08000000)
@@ -1099,11 +1505,21 @@ struct aac_bus_info_response { · 67 unmodified lines
10991505 #define AAC_OPT_SUPPLEMENT_ADAPTER_INFO cpu_to_le32(1<<16)
11001506 #define AAC_OPT_NEW_COMM cpu_to_le32(1<<17)
11011507 #define AAC_OPT_NEW_COMM_64 cpu_to_le32(1<<18)
1508+#define AAC_OPT_EXTENDED cpu_to_le32(1<<23)
1509+#define AAC_OPT_NATIVE_HBA cpu_to_le32(1<<25)
11021510 #define AAC_OPT_NEW_COMM_TYPE1 cpu_to_le32(1<<28)
11031511 #define AAC_OPT_NEW_COMM_TYPE2 cpu_to_le32(1<<29)
11041512 #define AAC_OPT_NEW_COMM_TYPE3 cpu_to_le32(1<<30)
11051513 #define AAC_OPT_NEW_COMM_TYPE4 cpu_to_le32(1<<31)
11061514
1515+#define AAC_COMM_PRODUCER 0
1516+#define AAC_COMM_MESSAGE 1
1517+#define AAC_COMM_MESSAGE_TYPE1 3
1518+#define AAC_COMM_MESSAGE_TYPE2 4
1519+#define AAC_COMM_MESSAGE_TYPE3 5
1520+
1521+#define AAC_EXTOPT_SA_FIRMWARE cpu_to_le32(1<<1)
1522+
11071523 /* MSIX context */
11081524 struct aac_msix_ctx {
11091525 int vector_no;
@@ -1119,15 +1535,17 @@ struct aac_dev · 9 unmodified lines
11191535 /*
11201536 * negotiated FIB settings
11211537 */
1122− unsigned max_fib_size;
1123− unsigned sg_tablesize;
1124− unsigned max_num_aif;
1538+ unsigned int max_fib_size;
1539+ unsigned int sg_tablesize;
1540+ unsigned int max_num_aif;
1541+
1542+ unsigned int max_cmd_size; /* max_fib_size or MAX_NATIVE */
11251543
11261544 /*
11271545 * Map for 128 fib objects (64k)
11281546 */
1129− dma_addr_t hw_fib_pa;
1130− struct hw_fib *hw_fib_va;
1547+ dma_addr_t hw_fib_pa; /* also used for native cmd */
1548+ struct hw_fib *hw_fib_va; /* also used for native cmd */
11311549 struct hw_fib *aif_base_va;
11321550 /*
11331551 * Fib Headers
@@ -1157,21 +1575,23 @@ struct aac_dev · 23 unmodified lines
11571575
11581576 resource_size_t base_size, dbg_size; /* Size of
11591577 * mapped in region */
1160−
1161− struct aac_init *init; /* Holds initialization info to communicate with adapter */
1578+ /*
1579+ * Holds initialization info
1580+ * to communicate with adapter
1581+ */
1582+ union aac_init *init;
11621583 dma_addr_t init_pa; /* Holds physical address of the init struct */
1163−
1164− u32 *host_rrq; /* response queue
1165− * if AAC_COMM_MESSAGE_TYPE1 */
1166−
1584+ /* response queue (if AAC_COMM_MESSAGE_TYPE1) */
1585+ __le32 *host_rrq;
11671586 dma_addr_t host_rrq_pa; /* phys. address */
11681587 /* index into rrq buffer */
11691588 u32 host_rrq_idx[AAC_MAX_MSIX];
11701589 atomic_t rrq_outstanding[AAC_MAX_MSIX];
11711590 u32 fibs_pushed_no;
11721591 struct pci_dev *pdev; /* Our PCI interface */
1173− void * printfbuf; /* pointer to buffer used for printf's from the adapter */
1174− void * comm_addr; /* Base address of Comm area */
1592+ /* pointer to buffer used for printf's from the adapter */
1593+ void *printfbuf;
1594+ void *comm_addr; /* Base address of Comm area */
11751595 dma_addr_t comm_phys; /* Physical Address of Comm area */
11761596 size_t comm_size;
11771597
@@ -1227,15 +1647,12 @@ struct aac_dev · 49 unmodified lines
12271647 u8 needs_dac;
12281648 u8 raid_scsi_mode;
12291649 u8 comm_interface;
1230−# define AAC_COMM_PRODUCER 0
1231−# define AAC_COMM_MESSAGE 1
1232−# define AAC_COMM_MESSAGE_TYPE1 3
1233−# define AAC_COMM_MESSAGE_TYPE2 4
12341650 u8 raw_io_interface;
12351651 u8 raw_io_64;
12361652 u8 printf_enabled;
12371653 u8 in_reset;
12381654 u8 msi;
1655+ u8 sa_firmware;
12391656 int management_fib_count;
12401657 spinlock_t manage_lock;
12411658 spinlock_t sync_lock;
@@ -1246,7 +1663,10 @@ struct aac_dev · 4 unmodified lines
12461663 u32 max_msix; /* max. MSI-X vectors */
12471664 u32 vector_cap; /* MSI-X vector capab.*/
12481665 int msi_enabled; /* MSI/MSI-X enabled */
1666+ atomic_t msix_counter;
1667+ struct msix_entry msixentry[AAC_MAX_MSIX];
12491668 struct aac_msix_ctx aac_msix[AAC_MAX_MSIX]; /* context */
1669+ struct aac_hba_map_info hba_map[AAC_MAX_BUSES][AAC_MAX_TARGETS];
12501670 u8 adapter_shutdown;
12511671 u32 handle_pci_error;
12521672 };
@@ -1269,8 +1689,8 @@ struct aac_dev · 16 unmodified lines
12691689 #define aac_adapter_check_health(dev) \
12701690 (dev)->a_ops.adapter_check_health(dev)
12711691
1272−#define aac_adapter_restart(dev,bled) \
1273− (dev)->a_ops.adapter_restart(dev,bled)
1692+#define aac_adapter_restart(dev, bled, reset_type) \
1693+ ((dev)->a_ops.adapter_restart(dev, bled, reset_type))
12741694
12751695 #define aac_adapter_start(dev) \
12761696 ((dev)->a_ops.adapter_start(dev))
@@ -1300,6 +1720,8 @@ struct aac_dev · 23 unmodified lines
13001720 #define FIB_CONTEXT_FLAG (0x00000002)
13011721 #define FIB_CONTEXT_FLAG_WAIT (0x00000004)
13021722 #define FIB_CONTEXT_FLAG_FASTRESP (0x00000008)
1723+#define FIB_CONTEXT_FLAG_NATIVE_HBA (0x00000010)
1724+#define FIB_CONTEXT_FLAG_NATIVE_HBA_TMF (0x00000020)
13031725
13041726 /*
13051727 * Define the command values
@@ -1358,6 +1780,7 @@ struct aac_dev · 52 unmodified lines
13581780 #define ST_IO 5
13591781 #define ST_NXIO 6
13601782 #define ST_E2BIG 7
1783+#define ST_MEDERR 8
13611784 #define ST_ACCES 13
13621785 #define ST_EXIST 17
13631786 #define ST_XDEV 18
@@ -1715,6 +2138,8 @@ struct aac_fsinfo { · 351 unmodified lines
17152138
17162139 struct aac_blockdevinfo {
17172140 __le32 block_size;
2141+ __le32 logical_phys_map;
2142+ u8 identifier[16];
17182143 };
17192144
17202145 union aac_contentinfo {
@@ -1940,6 +2365,15 @@ struct revision · 219 unmodified lines
19402365 #define FSACTL_FORCE_DELETE_DISK CTL_CODE(2120, METHOD_NEITHER)
19412366 #define FSACTL_GET_CONTAINERS 2131
19422367 #define FSACTL_SEND_LARGE_FIB CTL_CODE(2138, METHOD_BUFFERED)
2368+#define FSACTL_RESET_IOP CTL_CODE(2140, METHOD_BUFFERED)
2369+#define FSACTL_GET_HBA_INFO CTL_CODE(2150, METHOD_BUFFERED)
2370+/* flags defined for IOP & HW SOFT RESET */
2371+#define HW_IOP_RESET 0x01
2372+#define HW_SOFT_RESET 0x02
2373+#define IOP_HWSOFT_RESET (HW_IOP_RESET | HW_SOFT_RESET)
2374+/* HW Soft Reset register offset */
2375+#define IBW_SWR_OFFSET 0x4000
2376+#define SOFT_RESET_TIME 60
19432377
19442378
19452379 struct aac_common
@@ -1958,6 +2392,8 @@ struct aac_common · 12 unmodified lines
19582392 #ifdef DBG
19592393 u32 FibsSent;
19602394 u32 FibRecved;
2395+ u32 NativeSent;
2396+ u32 NativeRecved;
19612397 u32 NoResponseSent;
19622398 u32 NoResponseRecved;
19632399 u32 AsyncSent;
@@ -1969,6 +2405,56 @@ struct aac_common · 5 unmodified lines
19692405
19702406 extern struct aac_common aac_config;
19712407
2408+/*
2409+ * This is for management ioctl purpose only.
2410+ */
2411+struct aac_hba_info {
2412+
2413+ u8 driver_name[50];
2414+ u8 adapter_number;
2415+ u8 system_io_bus_number;
2416+ u8 device_number;
2417+ u32 function_number;
2418+ u32 vendor_id;
2419+ u32 device_id;
2420+ u32 sub_vendor_id;
2421+ u32 sub_system_id;
2422+ u32 mapped_base_address_size;
2423+ u32 base_physical_address_high_part;
2424+ u32 base_physical_address_low_part;
2425+
2426+ u32 max_command_size;
2427+ u32 max_fib_size;
2428+ u32 max_scatter_gather_from_os;
2429+ u32 max_scatter_gather_to_fw;
2430+ u32 max_outstanding_fibs;
2431+
2432+ u32 queue_start_threshold;
2433+ u32 queue_dump_threshold;
2434+ u32 max_io_size_queued;
2435+ u32 outstanding_io;
2436+
2437+ u32 firmware_build_number;
2438+ u32 bios_build_number;
2439+ u32 driver_build_number;
2440+ u32 serial_number_high_part;
2441+ u32 serial_number_low_part;
2442+ u32 supported_options;
2443+ u32 feature_bits;
2444+ u32 currentnumber_ports;
2445+
2446+ u8 new_comm_interface:1;
2447+ u8 new_commands_supported:1;
2448+ u8 disable_passthrough:1;
2449+ u8 expose_non_dasd:1;
2450+ u8 queue_allowed:1;
2451+ u8 bled_check_enabled:1;
2452+ u8 reserved1:1;
2453+ u8 reserted2:1;
2454+
2455+ u32 reserved3[10];
2456+
2457+};
19722458
19732459 /*
19742460 * The following macro is used when sending and receiving FIBs. It is
@@ -2096,9 +2582,10 @@ extern struct aac_common aac_config; · 121 unmodified lines
20962582
20972583 /* PMC NEW COMM: Request the event data */
20982584 #define AifReqEvent 200
2585+#define AifRawDeviceRemove 203 /* RAW device deleted */
2586+#define AifNativeDeviceAdd 204 /* native HBA device added */
2587+#define AifNativeDeviceRemove 205 /* native HBA device removed */
20992588
2100−/* RAW device deleted */
2101−#define AifRawDeviceRemove 203
21022589
21032590 /*
21042591 * Adapter Initiated FIB command structures. Start with the adapter
@@ -2131,6 +2618,8 @@ static inline unsigned int cap_to_cyls(sector_t capacity, unsigned divisor) · 26 unmodified lines
21312618
21322619 int aac_acquire_irq(struct aac_dev *dev);
21332620 void aac_free_irq(struct aac_dev *dev);
2621+int aac_report_phys_luns(struct aac_dev *dev, struct fib *fibptr, int rescan);
2622+int aac_issue_bmic_identify(struct aac_dev *dev, u32 bus, u32 target);
21342623 const char *aac_driverinfo(struct Scsi_Host *);
21352624 void aac_fib_vector_assign(struct aac_dev *dev);
21362625 struct fib *aac_fib_alloc(struct aac_dev *dev);
@@ -2141,9 +2630,12 @@ void aac_fib_free(struct fib * context); · 4 unmodified lines
21412630 void aac_fib_init(struct fib * context);
21422631 void aac_printf(struct aac_dev *dev, u32 val);
21432632 int aac_fib_send(u16 command, struct fib * context, unsigned long size, int priority, int wait, int reply, fib_callback callback, void *ctxt);
2633+int aac_hba_send(u8 command, struct fib *context,
2634+ fib_callback callback, void *ctxt);
21442635 int aac_consumer_get(struct aac_dev * dev, struct aac_queue * q, struct aac_entry **entry);
21452636 void aac_consumer_free(struct aac_dev * dev, struct aac_queue * q, u32 qnum);
21462637 int aac_fib_complete(struct fib * context);
2638+void aac_hba_callback(void *context, struct fib *fibptr);
21472639 #define fib_data(fibctx) ((void *)(fibctx)->hw_fib_va->data)
21482640 struct aac_dev *aac_init_adapter(struct aac_dev *dev);
21492641 void aac_src_access_devreg(struct aac_dev *dev, int mode);
@@ -2169,7 +2661,7 @@ unsigned int aac_command_normal(struct aac_queue * q); · 19 unmodified lines
21692661 unsigned int aac_intr_normal(struct aac_dev *dev, u32 Index,
21702662 int isAif, int isFastResponse,
21712663 struct hw_fib *aif_fib);
2172−int aac_reset_adapter(struct aac_dev * dev, int forced);
2664+int aac_reset_adapter(struct aac_dev *dev, int forced, u8 reset_type);
21732665 int aac_check_health(struct aac_dev * dev);
21742666 int aac_command_thread(void *data);
21752667 int aac_close_fib_context(struct aac_dev * dev, struct aac_fib_context *fibctx);
@@ -2183,7 +2675,6 @@ int aac_rx_select_comm(struct aac_dev *dev, int comm); · 7 unmodified lines
21832675 int aac_rx_deliver_producer(struct fib * fib);
21842676 char * get_container_type(unsigned type);
21852677 extern int numacb;
2186−extern int acbsize;
21872678 extern char aac_driver_version[];
21882679 extern int startup_timeout;
21892680 extern int aif_timeout;
@@ -2194,3 +2685,4 @@ extern int aac_commit; · 4 unmodified lines
21942685 extern int update_interval;
21952686 extern int check_interval;
21962687 extern int aac_check_reset;
2688+#endif
drivers/scsi/aacraid/commctrl.c+271−71
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -477,20 +478,24 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 464 unmodified lines
477478 struct fib* srbfib;
478479 int status;
479480 struct aac_srb *srbcmd = NULL;
481+ struct aac_hba_cmd_req *hbacmd = NULL;
480482 struct user_aac_srb *user_srbcmd = NULL;
481483 struct user_aac_srb __user *user_srb = arg;
482484 struct aac_srb_reply __user *user_reply;
483− struct aac_srb_reply* reply;
485+ u32 chn;
484486 u32 fibsize = 0;
485487 u32 flags = 0;
486488 s32 rcode = 0;
487489 u32 data_dir;
488− void __user *sg_user[32];
489− void *sg_list[32];
490+ void __user *sg_user[HBA_MAX_SG_EMBEDDED];
491+ void *sg_list[HBA_MAX_SG_EMBEDDED];
492+ u32 sg_count[HBA_MAX_SG_EMBEDDED];
490493 u32 sg_indx = 0;
491494 u32 byte_count = 0;
492495 u32 actual_fibsize64, actual_fibsize = 0;
493496 int i;
497+ int is_native_device;
498+ u64 address;
494499
495500
496501 if (dev->in_reset) {
@@ -507,11 +512,6 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 10 unmodified lines
507512 if (!(srbfib = aac_fib_alloc(dev))) {
508513 return -ENOMEM;
509514 }
510− aac_fib_init(srbfib);
511− /* raw_srb FIB is not FastResponseCapable */
512− srbfib->hw_fib_va->header.XferState &= ~cpu_to_le32(FastResponseCapable);
513−
514− srbcmd = (struct aac_srb*) fib_data(srbfib);
515515
516516 memset(sg_list, 0, sizeof(sg_list)); /* cleanup may take issue */
517517 if(copy_from_user(&fibsize, &user_srb->count,sizeof(u32))){
@@ -538,21 +538,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 20 unmodified lines
538538 goto cleanup;
539539 }
540540
541− user_reply = arg+fibsize;
542−
543541 flags = user_srbcmd->flags; /* from user in cpu order */
544− // Fix up srb for endian and force some values
545−
546− srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); // Force this
547− srbcmd->channel = cpu_to_le32(user_srbcmd->channel);
548− srbcmd->id = cpu_to_le32(user_srbcmd->id);
549− srbcmd->lun = cpu_to_le32(user_srbcmd->lun);
550− srbcmd->timeout = cpu_to_le32(user_srbcmd->timeout);
551− srbcmd->flags = cpu_to_le32(flags);
552− srbcmd->retry_limit = 0; // Obsolete parameter
553− srbcmd->cdb_size = cpu_to_le32(user_srbcmd->cdb_size);
554− memcpy(srbcmd->cdb, user_srbcmd->cdb, sizeof(srbcmd->cdb));
555−
556542 switch (flags & (SRB_DataIn | SRB_DataOut)) {
557543 case SRB_DataOut:
558544 data_dir = DMA_TO_DEVICE;
@@ -568,7 +554,12 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 9 unmodified lines
568554 }
569555 if (user_srbcmd->sg.count > ARRAY_SIZE(sg_list)) {
570556 dprintk((KERN_DEBUG"aacraid: too many sg entries %d\n",
571− le32_to_cpu(srbcmd->sg.count)));
557+ user_srbcmd->sg.count));
558+ rcode = -EINVAL;
559+ goto cleanup;
560+ }
561+ if ((data_dir == DMA_NONE) && user_srbcmd->sg.count) {
562+ dprintk((KERN_DEBUG"aacraid:SG with no direction specified\n"));
572563 rcode = -EINVAL;
573564 goto cleanup;
574565 }
@@ -588,13 +579,136 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 13 unmodified lines
588579 rcode = -EINVAL;
589580 goto cleanup;
590581 }
591− if ((data_dir == DMA_NONE) && user_srbcmd->sg.count) {
592− dprintk((KERN_DEBUG"aacraid: SG with no direction specified in Raw SRB command\n"));
593− rcode = -EINVAL;
594− goto cleanup;
582+
583+ chn = aac_logical_to_phys(user_srbcmd->channel);
584+ if (chn < AAC_MAX_BUSES && user_srbcmd->id < AAC_MAX_TARGETS &&
585+ dev->hba_map[chn][user_srbcmd->id].devtype ==
586+ AAC_DEVTYPE_NATIVE_RAW) {
587+ is_native_device = 1;
588+ hbacmd = (struct aac_hba_cmd_req *)srbfib->hw_fib_va;
589+ memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
590+
591+ /* iu_type is a parameter of aac_hba_send */
592+ switch (data_dir) {
593+ case DMA_TO_DEVICE:
594+ hbacmd->byte1 = 2;
595+ break;
596+ case DMA_FROM_DEVICE:
597+ case DMA_BIDIRECTIONAL:
598+ hbacmd->byte1 = 1;
599+ break;
600+ case DMA_NONE:
601+ default:
602+ break;
603+ }
604+ hbacmd->lun[1] = cpu_to_le32(user_srbcmd->lun);
605+ hbacmd->it_nexus = dev->hba_map[chn][user_srbcmd->id].rmw_nexus;
606+
607+ /*
608+ * we fill in reply_qid later in aac_src_deliver_message
609+ * we fill in iu_type, request_id later in aac_hba_send
610+ * we fill in emb_data_desc_count, data_length later
611+ * in sg list build
612+ */
613+
614+ memcpy(hbacmd->cdb, user_srbcmd->cdb, sizeof(hbacmd->cdb));
615+
616+ address = (u64)srbfib->hw_error_pa;
617+ hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
618+ hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
619+ hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
620+ hbacmd->emb_data_desc_count =
621+ cpu_to_le32(user_srbcmd->sg.count);
622+ srbfib->hbacmd_size = 64 +
623+ user_srbcmd->sg.count * sizeof(struct aac_hba_sgl);
624+
625+ } else {
626+ is_native_device = 0;
627+ aac_fib_init(srbfib);
628+
629+ /* raw_srb FIB is not FastResponseCapable */
630+ srbfib->hw_fib_va->header.XferState &=
631+ ~cpu_to_le32(FastResponseCapable);
632+
633+ srbcmd = (struct aac_srb *) fib_data(srbfib);
634+
635+ // Fix up srb for endian and force some values
636+
637+ srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); // Force this
638+ srbcmd->channel = cpu_to_le32(user_srbcmd->channel);
639+ srbcmd->id = cpu_to_le32(user_srbcmd->id);
640+ srbcmd->lun = cpu_to_le32(user_srbcmd->lun);
641+ srbcmd->timeout = cpu_to_le32(user_srbcmd->timeout);
642+ srbcmd->flags = cpu_to_le32(flags);
643+ srbcmd->retry_limit = 0; // Obsolete parameter
644+ srbcmd->cdb_size = cpu_to_le32(user_srbcmd->cdb_size);
645+ memcpy(srbcmd->cdb, user_srbcmd->cdb, sizeof(srbcmd->cdb));
595646 }
647+
596648 byte_count = 0;
597− if (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64) {
649+ if (is_native_device) {
650+ struct user_sgmap *usg32 = &user_srbcmd->sg;
651+ struct user_sgmap64 *usg64 =
652+ (struct user_sgmap64 *)&user_srbcmd->sg;
653+
654+ for (i = 0; i < usg32->count; i++) {
655+ void *p;
656+ u64 addr;
657+
658+ sg_count[i] = (actual_fibsize64 == fibsize) ?
659+ usg64->sg[i].count : usg32->sg[i].count;
660+ if (sg_count[i] >
661+ (dev->scsi_host_ptr->max_sectors << 9)) {
662+ pr_err("aacraid: upsg->sg[%d].count=%u>%u\n",
663+ i, sg_count[i],
664+ dev->scsi_host_ptr->max_sectors << 9);
665+ rcode = -EINVAL;
666+ goto cleanup;
667+ }
668+
669+ p = kmalloc(sg_count[i], GFP_KERNEL|__GFP_DMA);
670+ if (!p) {
671+ rcode = -ENOMEM;
672+ goto cleanup;
673+ }
674+
675+ if (actual_fibsize64 == fibsize) {
676+ addr = (u64)usg64->sg[i].addr[0];
677+ addr += ((u64)usg64->sg[i].addr[1]) << 32;
678+ } else {
679+ addr = (u64)usg32->sg[i].addr;
680+ }
681+
682+ sg_user[i] = (void __user *)(uintptr_t)addr;
683+ sg_list[i] = p; // save so we can clean up later
684+ sg_indx = i;
685+
686+ if (flags & SRB_DataOut) {
687+ if (copy_from_user(p, sg_user[i],
688+ sg_count[i])) {
689+ rcode = -EFAULT;
690+ goto cleanup;
691+ }
692+ }
693+ addr = pci_map_single(dev->pdev, p, sg_count[i],
694+ data_dir);
695+ hbacmd->sge[i].addr_hi = cpu_to_le32((u32)(addr>>32));
696+ hbacmd->sge[i].addr_lo = cpu_to_le32(
697+ (u32)(addr & 0xffffffff));
698+ hbacmd->sge[i].len = cpu_to_le32(sg_count[i]);
699+ hbacmd->sge[i].flags = 0;
700+ byte_count += sg_count[i];
701+ }
702+
703+ if (usg32->count > 0) /* embedded sglist */
704+ hbacmd->sge[usg32->count-1].flags =
705+ cpu_to_le32(0x40000000);
706+ hbacmd->data_length = cpu_to_le32(byte_count);
707+
708+ status = aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, srbfib,
709+ NULL, NULL);
710+
711+ } else if (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64) {
598712 struct user_sgmap64* upsg = (struct user_sgmap64*)&user_srbcmd->sg;
599713 struct sgmap64* psg = (struct sgmap64*)&srbcmd->sg;
600714
@@ -606,7 +720,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 5 unmodified lines
606720 for (i = 0; i < upsg->count; i++) {
607721 u64 addr;
608722 void* p;
609− if (upsg->sg[i].count >
723+
724+ sg_count[i] = upsg->sg[i].count;
725+ if (sg_count[i] >
610726 ((dev->adapter_info.options &
611727 AAC_OPT_NEW_COMM) ?
612728 (dev->scsi_host_ptr->max_sectors << 9) :
@@ -615,10 +731,10 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 2 unmodified lines
615731 goto cleanup;
616732 }
617733 /* Does this really need to be GFP_DMA? */
618− p = kmalloc(upsg->sg[i].count,GFP_KERNEL|__GFP_DMA);
734+ p = kmalloc(sg_count[i], GFP_KERNEL|__GFP_DMA);
619735 if(!p) {
620736 dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
621− upsg->sg[i].count,i,upsg->count));
737+ sg_count[i], i, upsg->count));
622738 rcode = -ENOMEM;
623739 goto cleanup;
624740 }
@@ -629,18 +745,20 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 4 unmodified lines
629745 sg_indx = i;
630746
631747 if (flags & SRB_DataOut) {
632− if(copy_from_user(p,sg_user[i],upsg->sg[i].count)){
748+ if (copy_from_user(p, sg_user[i],
749+ sg_count[i])){
633750 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
634751 rcode = -EFAULT;
635752 goto cleanup;
636753 }
637754 }
638− addr = pci_map_single(dev->pdev, p, upsg->sg[i].count, data_dir);
755+ addr = pci_map_single(dev->pdev, p,
756+ sg_count[i], data_dir);
639757
640758 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
641759 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
642− byte_count += upsg->sg[i].count;
643− psg->sg[i].count = cpu_to_le32(upsg->sg[i].count);
760+ byte_count += sg_count[i];
761+ psg->sg[i].count = cpu_to_le32(sg_count[i]);
644762 }
645763 } else {
646764 struct user_sgmap* usg;
@@ -657,7 +775,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 10 unmodified lines
657775 for (i = 0; i < usg->count; i++) {
658776 u64 addr;
659777 void* p;
660− if (usg->sg[i].count >
778+
779+ sg_count[i] = usg->sg[i].count;
780+ if (sg_count[i] >
661781 ((dev->adapter_info.options &
662782 AAC_OPT_NEW_COMM) ?
663783 (dev->scsi_host_ptr->max_sectors << 9) :
@@ -667,10 +787,10 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 3 unmodified lines
667787 goto cleanup;
668788 }
669789 /* Does this really need to be GFP_DMA? */
670− p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA);
790+ p = kmalloc(sg_count[i], GFP_KERNEL|__GFP_DMA);
671791 if(!p) {
672792 dprintk((KERN_DEBUG "aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
673− usg->sg[i].count,i,usg->count));
793+ sg_count[i], i, usg->count));
674794 kfree(usg);
675795 rcode = -ENOMEM;
676796 goto cleanup;
@@ -680,19 +800,21 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 3 unmodified lines
680800 sg_indx = i;
681801
682802 if (flags & SRB_DataOut) {
683− if(copy_from_user(p,sg_user[i],upsg->sg[i].count)){
803+ if (copy_from_user(p, sg_user[i],
804+ sg_count[i])) {
684805 kfree (usg);
685806 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
686807 rcode = -EFAULT;
687808 goto cleanup;
688809 }
689810 }
690− addr = pci_map_single(dev->pdev, p, usg->sg[i].count, data_dir);
811+ addr = pci_map_single(dev->pdev, p,
812+ sg_count[i], data_dir);
691813
692814 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
693815 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
694− byte_count += usg->sg[i].count;
695− psg->sg[i].count = cpu_to_le32(usg->sg[i].count);
816+ byte_count += sg_count[i];
817+ psg->sg[i].count = cpu_to_le32(sg_count[i]);
696818 }
697819 kfree (usg);
698820 }
@@ -711,7 +833,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 12 unmodified lines
711833 for (i = 0; i < upsg->count; i++) {
712834 uintptr_t addr;
713835 void* p;
714− if (usg->sg[i].count >
836+
837+ sg_count[i] = usg->sg[i].count;
838+ if (sg_count[i] >
715839 ((dev->adapter_info.options &
716840 AAC_OPT_NEW_COMM) ?
717841 (dev->scsi_host_ptr->max_sectors << 9) :
@@ -720,10 +844,10 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 2 unmodified lines
720844 goto cleanup;
721845 }
722846 /* Does this really need to be GFP_DMA? */
723− p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA);
724− if(!p) {
847+ p = kmalloc(sg_count[i], GFP_KERNEL|__GFP_DMA);
848+ if (!p) {
725849 dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
726− usg->sg[i].count,i,usg->count));
850+ sg_count[i], i, usg->count));
727851 rcode = -ENOMEM;
728852 goto cleanup;
729853 }
@@ -734,7 +858,8 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 4 unmodified lines
734858 sg_indx = i;
735859
736860 if (flags & SRB_DataOut) {
737− if(copy_from_user(p,sg_user[i],usg->sg[i].count)){
861+ if (copy_from_user(p, sg_user[i],
862+ sg_count[i])){
738863 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
739864 rcode = -EFAULT;
740865 goto cleanup;
@@ -744,13 +869,15 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 3 unmodified lines
744869
745870 psg->sg[i].addr = cpu_to_le32(addr & 0xffffffff);
746871 byte_count += usg->sg[i].count;
747− psg->sg[i].count = cpu_to_le32(usg->sg[i].count);
872+ psg->sg[i].count = cpu_to_le32(sg_count[i]);
748873 }
749874 } else {
750875 for (i = 0; i < upsg->count; i++) {
751876 dma_addr_t addr;
752877 void* p;
753− if (upsg->sg[i].count >
878+
879+ sg_count[i] = upsg->sg[i].count;
880+ if (sg_count[i] >
754881 ((dev->adapter_info.options &
755882 AAC_OPT_NEW_COMM) ?
756883 (dev->scsi_host_ptr->max_sectors << 9) :
@@ -758,10 +885,10 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 1 unmodified line
758885 rcode = -EINVAL;
759886 goto cleanup;
760887 }
761− p = kmalloc(upsg->sg[i].count, GFP_KERNEL);
888+ p = kmalloc(sg_count[i], GFP_KERNEL);
762889 if (!p) {
763890 dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
764− upsg->sg[i].count, i, upsg->count));
891+ sg_count[i], i, upsg->count));
765892 rcode = -ENOMEM;
766893 goto cleanup;
767894 }
@@ -770,19 +897,19 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 2 unmodified lines
770897 sg_indx = i;
771898
772899 if (flags & SRB_DataOut) {
773− if(copy_from_user(p, sg_user[i],
774− upsg->sg[i].count)) {
900+ if (copy_from_user(p, sg_user[i],
901+ sg_count[i])) {
775902 dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
776903 rcode = -EFAULT;
777904 goto cleanup;
778905 }
779906 }
780907 addr = pci_map_single(dev->pdev, p,
781− upsg->sg[i].count, data_dir);
908+ sg_count[i], data_dir);
782909
783910 psg->sg[i].addr = cpu_to_le32(addr);
784− byte_count += upsg->sg[i].count;
785− psg->sg[i].count = cpu_to_le32(upsg->sg[i].count);
911+ byte_count += sg_count[i];
912+ psg->sg[i].count = cpu_to_le32(sg_count[i]);
786913 }
787914 }
788915 srbcmd->count = cpu_to_le32(byte_count);
@@ -792,12 +919,13 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 3 unmodified lines
792919 psg->count = 0;
793920 status = aac_fib_send(ScsiPortCommand, srbfib, actual_fibsize, FsaNormal, 1, 1, NULL, NULL);
794921 }
922+
795923 if (status == -ERESTARTSYS) {
796924 rcode = -ERESTARTSYS;
797925 goto cleanup;
798926 }
799927
800− if (status != 0){
928+ if (status != 0) {
801929 dprintk((KERN_DEBUG"aacraid: Could not send raw srb fib to hba\n"));
802930 rcode = -ENXIO;
803931 goto cleanup;
@@ -805,11 +933,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 1 unmodified line
805933
806934 if (flags & SRB_DataIn) {
807935 for(i = 0 ; i <= sg_indx; i++){
808− byte_count = le32_to_cpu(
809− (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)
810− ? ((struct sgmap64*)&srbcmd->sg)->sg[i].count
811− : srbcmd->sg.sg[i].count);
812− if(copy_to_user(sg_user[i], sg_list[i], byte_count)){
936+ if (copy_to_user(sg_user[i], sg_list[i], sg_count[i])) {
813937 dprintk((KERN_DEBUG"aacraid: Could not copy sg data to user\n"));
814938 rcode = -EFAULT;
815939 goto cleanup;
@@ -818,19 +942,50 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · 2 unmodified lines
818942 }
819943 }
820944
821− reply = (struct aac_srb_reply *) fib_data(srbfib);
822− if(copy_to_user(user_reply,reply,sizeof(struct aac_srb_reply))){
823− dprintk((KERN_DEBUG"aacraid: Could not copy reply to user\n"));
824− rcode = -EFAULT;
825− goto cleanup;
945+ user_reply = arg + fibsize;
946+ if (is_native_device) {
947+ struct aac_hba_resp *err =
948+ &((struct aac_native_hba *)srbfib->hw_fib_va)->resp.err;
949+ struct aac_srb_reply reply;
950+
951+ reply.status = ST_OK;
952+ if (srbfib->flags & FIB_CONTEXT_FLAG_FASTRESP) {
953+ /* fast response */
954+ reply.srb_status = SRB_STATUS_SUCCESS;
955+ reply.scsi_status = 0;
956+ reply.data_xfer_length = byte_count;
957+ } else {
958+ reply.srb_status = err->service_response;
959+ reply.scsi_status = err->status;
960+ reply.data_xfer_length = byte_count -
961+ le32_to_cpu(err->residual_count);
962+ reply.sense_data_size = err->sense_response_data_len;
963+ memcpy(reply.sense_data, err->sense_response_buf,
964+ AAC_SENSE_BUFFERSIZE);
965+ }
966+ if (copy_to_user(user_reply, &reply,
967+ sizeof(struct aac_srb_reply))) {
968+ dprintk((KERN_DEBUG"aacraid: Copy to user failed\n"));
969+ rcode = -EFAULT;
970+ goto cleanup;
971+ }
972+ } else {
973+ struct aac_srb_reply *reply;
974+
975+ reply = (struct aac_srb_reply *) fib_data(srbfib);
976+ if (copy_to_user(user_reply, reply,
977+ sizeof(struct aac_srb_reply))) {
978+ dprintk((KERN_DEBUG"aacraid: Copy to user failed\n"));
979+ rcode = -EFAULT;
980+ goto cleanup;
981+ }
826982 }
827983
828984 cleanup:
829985 kfree(user_srbcmd);
830− for(i=0; i <= sg_indx; i++){
831− kfree(sg_list[i]);
832− }
833986 if (rcode != -ERESTARTSYS) {
987+ for (i = 0; i <= sg_indx; i++)
988+ kfree(sg_list[i]);
834989 aac_fib_complete(srbfib);
835990 aac_fib_free(srbfib);
836991 }
@@ -858,6 +1013,44 @@ static int aac_get_pci_info(struct aac_dev* dev, void __user *arg) · 21 unmodified lines
8581013 return 0;
8591014 }
8601015
1016+static int aac_get_hba_info(struct aac_dev *dev, void __user *arg)
1017+{
1018+ struct aac_hba_info hbainfo;
1019+
1020+ hbainfo.adapter_number = (u8) dev->id;
1021+ hbainfo.system_io_bus_number = dev->pdev->bus->number;
1022+ hbainfo.device_number = (dev->pdev->devfn >> 3);
1023+ hbainfo.function_number = (dev->pdev->devfn & 0x0007);
1024+
1025+ hbainfo.vendor_id = dev->pdev->vendor;
1026+ hbainfo.device_id = dev->pdev->device;
1027+ hbainfo.sub_vendor_id = dev->pdev->subsystem_vendor;
1028+ hbainfo.sub_system_id = dev->pdev->subsystem_device;
1029+
1030+ if (copy_to_user(arg, &hbainfo, sizeof(struct aac_hba_info))) {
1031+ dprintk((KERN_DEBUG "aacraid: Could not copy hba info\n"));
1032+ return -EFAULT;
1033+ }
1034+
1035+ return 0;
1036+}
1037+
1038+struct aac_reset_iop {
1039+ u8 reset_type;
1040+};
1041+
1042+static int aac_send_reset_adapter(struct aac_dev *dev, void __user *arg)
1043+{
1044+ struct aac_reset_iop reset;
1045+ int retval;
1046+
1047+ if (copy_from_user((void *)&reset, arg, sizeof(struct aac_reset_iop)))
1048+ return -EFAULT;
1049+
1050+ retval = aac_reset_adapter(dev, 0, reset.reset_type);
1051+ return retval;
1052+
1053+}
8611054
8621055 int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg)
8631056 {
@@ -901,6 +1094,13 @@ int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg) · 37 unmodified lines
9011094 case FSACTL_GET_PCI_INFO:
9021095 status = aac_get_pci_info(dev,arg);
9031096 break;
1097+ case FSACTL_GET_HBA_INFO:
1098+ status = aac_get_hba_info(dev, arg);
1099+ break;
1100+ case FSACTL_RESET_IOP:
1101+ status = aac_send_reset_adapter(dev, arg);
1102+ break;
1103+
9041104 default:
9051105 status = -ENOTTY;
9061106 break;
drivers/scsi/aacraid/comminit.c+190−140
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -72,104 +73,175 @@ static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long co · 59 unmodified lines
7273 unsigned long size, align;
7374 const unsigned long fibsize = dev->max_fib_size;
7475 const unsigned long printfbufsiz = 256;
75− unsigned long host_rrq_size = 0;
76− struct aac_init *init;
76+ unsigned long host_rrq_size, aac_init_size;
77+ union aac_init *init;
7778 dma_addr_t phys;
7879 unsigned long aac_max_hostphysmempages;
7980
80− if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
81− dev->comm_interface == AAC_COMM_MESSAGE_TYPE2)
81+ if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) ||
82+ (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) ||
83+ (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3 &&
84+ !dev->sa_firmware)) {
85+ host_rrq_size =
86+ (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB)
87+ * sizeof(u32);
88+ aac_init_size = sizeof(union aac_init);
89+ } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3 &&
90+ dev->sa_firmware) {
8291 host_rrq_size = (dev->scsi_host_ptr->can_queue
83− + AAC_NUM_MGT_FIB) * sizeof(u32);
84− size = fibsize + sizeof(struct aac_init) + commsize +
85− commalign + printfbufsiz + host_rrq_size;
86−
92+ + AAC_NUM_MGT_FIB) * sizeof(u32) * AAC_MAX_MSIX;
93+ aac_init_size = sizeof(union aac_init) +
94+ (AAC_MAX_HRRQ - 1) * sizeof(struct _rrq);
95+ } else {
96+ host_rrq_size = 0;
97+ aac_init_size = sizeof(union aac_init);
98+ }
99+ size = fibsize + aac_init_size + commsize + commalign +
100+ printfbufsiz + host_rrq_size;
101+
87102 base = pci_alloc_consistent(dev->pdev, size, &phys);
88103
89− if(base == NULL)
90− {
104+ if (base == NULL) {
91105 printk(KERN_ERR "aacraid: unable to create mapping.\n");
92106 return 0;
93107 }
108+
94109 dev->comm_addr = (void *)base;
95110 dev->comm_phys = phys;
96111 dev->comm_size = size;
97−
98− if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
99− dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
112+
113+ if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) ||
114+ (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) ||
115+ (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3)) {
100116 dev->host_rrq = (u32 *)(base + fibsize);
101117 dev->host_rrq_pa = phys + fibsize;
102118 memset(dev->host_rrq, 0, host_rrq_size);
103119 }
104120
105− dev->init = (struct aac_init *)(base + fibsize + host_rrq_size);
121+ dev->init = (union aac_init *)(base + fibsize + host_rrq_size);
106122 dev->init_pa = phys + fibsize + host_rrq_size;
107123
108124 init = dev->init;
109125
110− init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
111− if (dev->max_fib_size != sizeof(struct hw_fib))
112− init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
113− init->Sa_MSIXVectors = cpu_to_le32(SA_INIT_NUM_MSIXVECTORS);
114− init->fsrev = cpu_to_le32(dev->fsrev);
126+ if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) {
127+ int i;
128+ u64 addr;
129+
130+ init->r8.init_struct_revision =
131+ cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_8);
132+ init->r8.init_flags = cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
133+ INITFLAGS_DRIVER_USES_UTC_TIME |
134+ INITFLAGS_DRIVER_SUPPORTS_PM);
135+ init->r8.init_flags |=
136+ cpu_to_le32(INITFLAGS_DRIVER_SUPPORTS_HBA_MODE);
137+ init->r8.rr_queue_count = cpu_to_le32(dev->max_msix);
138+ init->r8.max_io_size =
139+ cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
140+ init->r8.max_num_aif = init->r8.reserved1 =
141+ init->r8.reserved2 = 0;
142+
143+ for (i = 0; i < dev->max_msix; i++) {
144+ addr = (u64)dev->host_rrq_pa + dev->vector_cap * i *
145+ sizeof(u32);
146+ init->r8.rrq[i].host_addr_high = cpu_to_le32(
147+ upper_32_bits(addr));
148+ init->r8.rrq[i].host_addr_low = cpu_to_le32(
149+ lower_32_bits(addr));
150+ init->r8.rrq[i].msix_id = i;
151+ init->r8.rrq[i].element_count = cpu_to_le16(
152+ (u16)dev->vector_cap);
153+ init->r8.rrq[i].comp_thresh =
154+ init->r8.rrq[i].unused = 0;
155+ }
115156
116− /*
117− * Adapter Fibs are the first thing allocated so that they
118− * start page aligned
119− */
120− dev->aif_base_va = (struct hw_fib *)base;
121−
122− init->AdapterFibsVirtualAddress = 0;
123− init->AdapterFibsPhysicalAddress = cpu_to_le32((u32)phys);
124− init->AdapterFibsSize = cpu_to_le32(fibsize);
125− init->AdapterFibAlign = cpu_to_le32(sizeof(struct hw_fib));
126− /*
127− * number of 4k pages of host physical memory. The aacraid fw needs
128− * this number to be less than 4gb worth of pages. New firmware doesn't
129− * have any issues with the mapping system, but older Firmware did, and
130− * had *troubles* dealing with the math overloading past 32 bits, thus
131− * we must limit this field.
132− */
133− aac_max_hostphysmempages = dma_get_required_mask(&dev->pdev->dev) >> 12;
134− if (aac_max_hostphysmempages < AAC_MAX_HOSTPHYSMEMPAGES)
135− init->HostPhysMemPages = cpu_to_le32(aac_max_hostphysmempages);
136− else
137− init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
138−
139− init->InitFlags = cpu_to_le32(INITFLAGS_DRIVER_USES_UTC_TIME |
140− INITFLAGS_DRIVER_SUPPORTS_PM);
141− init->MaxIoCommands = cpu_to_le32(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
142− init->MaxIoSize = cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
143− init->MaxFibSize = cpu_to_le32(dev->max_fib_size);
144− init->MaxNumAif = cpu_to_le32(dev->max_num_aif);
145−
146− if (dev->comm_interface == AAC_COMM_MESSAGE) {
147− init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
148− dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
149− } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) {
150− init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_6);
151− init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
152− INITFLAGS_NEW_COMM_TYPE1_SUPPORTED | INITFLAGS_FAST_JBOD_SUPPORTED);
153− init->HostRRQ_AddrHigh = cpu_to_le32((u32)((u64)dev->host_rrq_pa >> 32));
154− init->HostRRQ_AddrLow = cpu_to_le32((u32)(dev->host_rrq_pa & 0xffffffff));
155− dprintk((KERN_WARNING"aacraid: New Comm Interface type1 enabled\n"));
156− } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
157− init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_7);
158− init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
159− INITFLAGS_NEW_COMM_TYPE2_SUPPORTED | INITFLAGS_FAST_JBOD_SUPPORTED);
160− init->HostRRQ_AddrHigh = cpu_to_le32((u32)((u64)dev->host_rrq_pa >> 32));
161− init->HostRRQ_AddrLow = cpu_to_le32((u32)(dev->host_rrq_pa & 0xffffffff));
162− /* number of MSI-X */
163− init->Sa_MSIXVectors = cpu_to_le32(dev->max_msix);
164− dprintk((KERN_WARNING"aacraid: New Comm Interface type2 enabled\n"));
157+ pr_warn("aacraid: Comm Interface type3 enabled\n");
158+ } else {
159+ init->r7.init_struct_revision =
160+ cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
161+ if (dev->max_fib_size != sizeof(struct hw_fib))
162+ init->r7.init_struct_revision =
163+ cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
164+ init->r7.no_of_msix_vectors = cpu_to_le32(SA_MINIPORT_REVISION);
165+ init->r7.fsrev = cpu_to_le32(dev->fsrev);
166+
167+ /*
168+ * Adapter Fibs are the first thing allocated so that they
169+ * start page aligned
170+ */
171+ dev->aif_base_va = (struct hw_fib *)base;
172+
173+ init->r7.adapter_fibs_virtual_address = 0;
174+ init->r7.adapter_fibs_physical_address = cpu_to_le32((u32)phys);
175+ init->r7.adapter_fibs_size = cpu_to_le32(fibsize);
176+ init->r7.adapter_fib_align = cpu_to_le32(sizeof(struct hw_fib));
177+
178+ /*
179+ * number of 4k pages of host physical memory. The aacraid fw
180+ * needs this number to be less than 4gb worth of pages. New
181+ * firmware doesn't have any issues with the mapping system, but
182+ * older Firmware did, and had *troubles* dealing with the math
183+ * overloading past 32 bits, thus we must limit this field.
184+ */
185+ aac_max_hostphysmempages =
186+ dma_get_required_mask(&dev->pdev->dev) >> 12;
187+ if (aac_max_hostphysmempages < AAC_MAX_HOSTPHYSMEMPAGES)
188+ init->r7.host_phys_mem_pages =
189+ cpu_to_le32(aac_max_hostphysmempages);
190+ else
191+ init->r7.host_phys_mem_pages =
192+ cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
193+
194+ init->r7.init_flags =
195+ cpu_to_le32(INITFLAGS_DRIVER_USES_UTC_TIME |
196+ INITFLAGS_DRIVER_SUPPORTS_PM);
197+ init->r7.max_io_commands =
198+ cpu_to_le32(dev->scsi_host_ptr->can_queue +
199+ AAC_NUM_MGT_FIB);
200+ init->r7.max_io_size =
201+ cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
202+ init->r7.max_fib_size = cpu_to_le32(dev->max_fib_size);
203+ init->r7.max_num_aif = cpu_to_le32(dev->max_num_aif);
204+
205+ if (dev->comm_interface == AAC_COMM_MESSAGE) {
206+ init->r7.init_flags |=
207+ cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
208+ pr_warn("aacraid: Comm Interface enabled\n");
209+ } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) {
210+ init->r7.init_struct_revision =
211+ cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_6);
212+ init->r7.init_flags |=
213+ cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
214+ INITFLAGS_NEW_COMM_TYPE1_SUPPORTED |
215+ INITFLAGS_FAST_JBOD_SUPPORTED);
216+ init->r7.host_rrq_addr_high =
217+ cpu_to_le32(upper_32_bits(dev->host_rrq_pa));
218+ init->r7.host_rrq_addr_low =
219+ cpu_to_le32(lower_32_bits(dev->host_rrq_pa));
220+ pr_warn("aacraid: Comm Interface type1 enabled\n");
221+ } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
222+ init->r7.init_struct_revision =
223+ cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_7);
224+ init->r7.init_flags |=
225+ cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
226+ INITFLAGS_NEW_COMM_TYPE2_SUPPORTED |
227+ INITFLAGS_FAST_JBOD_SUPPORTED);
228+ init->r7.host_rrq_addr_high =
229+ cpu_to_le32(upper_32_bits(dev->host_rrq_pa));
230+ init->r7.host_rrq_addr_low =
231+ cpu_to_le32(lower_32_bits(dev->host_rrq_pa));
232+ init->r7.no_of_msix_vectors =
233+ cpu_to_le32(dev->max_msix);
234+ /* must be the COMM_PREFERRED_SETTINGS values */
235+ pr_warn("aacraid: Comm Interface type2 enabled\n");
236+ }
165237 }
166238
167239 /*
168240 * Increment the base address by the amount already used
169241 */
170− base = base + fibsize + host_rrq_size + sizeof(struct aac_init);
242+ base = base + fibsize + host_rrq_size + aac_init_size;
171243 phys = (dma_addr_t)((ulong)phys + fibsize + host_rrq_size +
172− sizeof(struct aac_init));
244+ aac_init_size);
173245
174246 /*
175247 * Align the beginning of Headers to commalign
@@ -181,7 +253,8 @@ static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long co · 5 unmodified lines
181253 * Fill in addresses of the Comm Area Headers and Queues
182254 */
183255 *commaddr = base;
184− init->CommHeaderAddress = cpu_to_le32((u32)phys);
256+ if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE3)
257+ init->r7.comm_header_address = cpu_to_le32((u32)phys);
185258 /*
186259 * Increment the base address by the size of the CommArea
187260 */
@@ -191,12 +264,14 @@ static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long co · 3 unmodified lines
191264 * Place the Printf buffer area after the Fast I/O comm area.
192265 */
193266 dev->printfbuf = (void *)base;
194− init->printfbuf = cpu_to_le32(phys);
195− init->printfbufsiz = cpu_to_le32(printfbufsiz);
267+ if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE3) {
268+ init->r7.printfbuf = cpu_to_le32(phys);
269+ init->r7.printfbufsiz = cpu_to_le32(printfbufsiz);
270+ }
196271 memset(base, 0, printfbufsiz);
197272 return 1;
198273 }
199−
274+
200275 static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize)
201276 {
202277 atomic_set(&q->numpending, 0);
@@ -404,9 +479,13 @@ void aac_define_int_mode(struct aac_dev *dev) · 201 unmodified lines
404479 if (dev->max_msix > msi_count)
405480 dev->max_msix = msi_count;
406481 }
407− dev->vector_cap =
408− (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) /
409− msi_count;
482+ if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3 && dev->sa_firmware)
483+ dev->vector_cap = dev->scsi_host_ptr->can_queue +
484+ AAC_NUM_MGT_FIB;
485+ else
486+ dev->vector_cap = (dev->scsi_host_ptr->can_queue +
487+ AAC_NUM_MGT_FIB) / msi_count;
488+
410489 }
411490 struct aac_dev *aac_init_adapter(struct aac_dev *dev)
412491 {
@@ -440,30 +519,37 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev) · 27 unmodified lines
440519
441520 if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
442521 0, 0, 0, 0, 0, 0,
443− status+0, status+1, status+2, status+3, NULL)) &&
444− (status[0] == 0x00000001)) {
522+ status+0, status+1, status+2, status+3, status+4)) &&
523+ (status[0] == 0x00000001)) {
445524 dev->doorbell_mask = status[3];
446− if (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_64))
525+ if (status[1] & AAC_OPT_NEW_COMM_64)
447526 dev->raw_io_64 = 1;
448527 dev->sync_mode = aac_sync_mode;
449528 if (dev->a_ops.adapter_comm &&
450− (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM))) {
529+ (status[1] & AAC_OPT_NEW_COMM)) {
451530 dev->comm_interface = AAC_COMM_MESSAGE;
452531 dev->raw_io_interface = 1;
453− if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE1))) {
532+ if ((status[1] & AAC_OPT_NEW_COMM_TYPE1)) {
454533 /* driver supports TYPE1 (Tupelo) */
455534 dev->comm_interface = AAC_COMM_MESSAGE_TYPE1;
456− } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE2))) {
457− /* driver supports TYPE2 (Denali) */
535+ } else if (status[1] & AAC_OPT_NEW_COMM_TYPE2) {
536+ /* driver supports TYPE2 (Denali, Yosemite) */
458537 dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
459− } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE4)) ||
460− (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE3))) {
461− /* driver doesn't TYPE3 and TYPE4 */
462− /* switch to sync. mode */
538+ } else if (status[1] & AAC_OPT_NEW_COMM_TYPE3) {
539+ /* driver supports TYPE3 (Yosemite, Thor) */
540+ dev->comm_interface = AAC_COMM_MESSAGE_TYPE3;
541+ } else if (status[1] & AAC_OPT_NEW_COMM_TYPE4) {
542+ /* not supported TYPE - switch to sync. mode */
463543 dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
464544 dev->sync_mode = 1;
465545 }
466546 }
547+ if ((status[1] & le32_to_cpu(AAC_OPT_EXTENDED)) &&
548+ (status[4] & le32_to_cpu(AAC_EXTOPT_SA_FIRMWARE)))
549+ dev->sa_firmware = 1;
550+ else
551+ dev->sa_firmware = 0;
552+
467553 if ((dev->comm_interface == AAC_COMM_MESSAGE) &&
468554 (status[2] > dev->base_size)) {
469555 aac_adapter_ioremap(dev, 0);
@@ -500,61 +586,25 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev) · 30 unmodified lines
500586 dev->sg_tablesize = status[2] & 0xFFFF;
501587 if (dev->pdev->device == PMC_DEVICE_S7 ||
502588 dev->pdev->device == PMC_DEVICE_S8 ||
503− dev->pdev->device == PMC_DEVICE_S9)
504− host->can_queue = ((status[3] >> 16) ? (status[3] >> 16) :
505− (status[3] & 0xFFFF)) - AAC_NUM_MGT_FIB;
506− else
507− host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB;
589+ dev->pdev->device == PMC_DEVICE_S9) {
590+ if (host->can_queue > (status[3] >> 16) -
591+ AAC_NUM_MGT_FIB)
592+ host->can_queue = (status[3] >> 16) -
593+ AAC_NUM_MGT_FIB;
594+ } else if (host->can_queue > (status[3] & 0xFFFF) -
595+ AAC_NUM_MGT_FIB)
596+ host->can_queue = (status[3] & 0xFFFF) -
597+ AAC_NUM_MGT_FIB;
598+
508599 dev->max_num_aif = status[4] & 0xFFFF;
509− /*
510− * NOTE:
511− * All these overrides are based on a fixed internal
512− * knowledge and understanding of existing adapters,
513− * acbsize should be set with caution.
514− */
515− if (acbsize == 512) {
516− host->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
517− dev->max_fib_size = 512;
518− dev->sg_tablesize = host->sg_tablesize
519− = (512 - sizeof(struct aac_fibhdr)
520− - sizeof(struct aac_write) + sizeof(struct sgentry))
521− / sizeof(struct sgentry);
522− host->can_queue = AAC_NUM_IO_FIB;
523− } else if (acbsize == 2048) {
524− host->max_sectors = 512;
525− dev->max_fib_size = 2048;
526− host->sg_tablesize = 65;
527− dev->sg_tablesize = 81;
528− host->can_queue = 512 - AAC_NUM_MGT_FIB;
529− } else if (acbsize == 4096) {
530− host->max_sectors = 1024;
531− dev->max_fib_size = 4096;
532− host->sg_tablesize = 129;
533− dev->sg_tablesize = 166;
534− host->can_queue = 256 - AAC_NUM_MGT_FIB;
535− } else if (acbsize == 8192) {
536− host->max_sectors = 2048;
537− dev->max_fib_size = 8192;
538− host->sg_tablesize = 257;
539− dev->sg_tablesize = 337;
540− host->can_queue = 128 - AAC_NUM_MGT_FIB;
541− } else if (acbsize > 0) {
542− printk("Illegal acbsize=%d ignored\n", acbsize);
543− }
544600 }
545− {
546−
547− if (numacb > 0) {
548− if (numacb < host->can_queue)
549− host->can_queue = numacb;
550− else
551− printk("numacb=%d ignored\n", numacb);
552− }
601+ if (numacb > 0) {
602+ if (numacb < host->can_queue)
603+ host->can_queue = numacb;
604+ else
605+ pr_warn("numacb=%d ignored\n", numacb);
553606 }
554607
555− if (host->can_queue > AAC_NUM_IO_FIB)
556− host->can_queue = AAC_NUM_IO_FIB;
557−
558608 if (dev->pdev->device == PMC_DEVICE_S6 ||
559609 dev->pdev->device == PMC_DEVICE_S7 ||
560610 dev->pdev->device == PMC_DEVICE_S8 ||
drivers/scsi/aacraid/commsup.c+705−259
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -43,6 +44,7 @@ · 30 unmodified lines
4344 #include <linux/kthread.h>
4445 #include <linux/interrupt.h>
4546 #include <linux/semaphore.h>
47+#include <linux/bcd.h>
4648 #include <scsi/scsi.h>
4749 #include <scsi/scsi_host.h>
4850 #include <scsi/scsi_device.h>
@@ -60,12 +62,22 @@ · 11 unmodified lines
6062
6163 static int fib_map_alloc(struct aac_dev *dev)
6264 {
65+ if (dev->max_fib_size > AAC_MAX_NATIVE_SIZE)
66+ dev->max_cmd_size = AAC_MAX_NATIVE_SIZE;
67+ else
68+ dev->max_cmd_size = dev->max_fib_size;
69+ if (dev->max_fib_size < AAC_MAX_NATIVE_SIZE) {
70+ dev->max_cmd_size = AAC_MAX_NATIVE_SIZE;
71+ } else {
72+ dev->max_cmd_size = dev->max_fib_size;
73+ }
74+
6375 dprintk((KERN_INFO
6476 "allocate hardware fibs pci_alloc_consistent(%p, %d * (%d + %d), %p)\n",
65− dev->pdev, dev->max_fib_size, dev->scsi_host_ptr->can_queue,
77+ dev->pdev, dev->max_cmd_size, dev->scsi_host_ptr->can_queue,
6678 AAC_NUM_MGT_FIB, &dev->hw_fib_pa));
6779 dev->hw_fib_va = pci_alloc_consistent(dev->pdev,
68− (dev->max_fib_size + sizeof(struct aac_fib_xporthdr))
80+ (dev->max_cmd_size + sizeof(struct aac_fib_xporthdr))
6981 * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) + (ALIGN32 - 1),
7082 &dev->hw_fib_pa);
7183 if (dev->hw_fib_va == NULL)
@@ -83,9 +95,9 @@ static int fib_map_alloc(struct aac_dev *dev) · 11 unmodified lines
8395
8496 void aac_fib_map_free(struct aac_dev *dev)
8597 {
86− if (dev->hw_fib_va && dev->max_fib_size) {
98+ if (dev->hw_fib_va && dev->max_cmd_size) {
8799 pci_free_consistent(dev->pdev,
88− (dev->max_fib_size *
100+ (dev->max_cmd_size *
89101 (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB)),
90102 dev->hw_fib_va, dev->hw_fib_pa);
91103 }
@@ -129,11 +141,14 @@ int aac_fib_setup(struct aac_dev * dev) · 37 unmodified lines
129141 struct hw_fib *hw_fib;
130142 dma_addr_t hw_fib_pa;
131143 int i;
144+ u32 max_cmds;
132145
133146 while (((i = fib_map_alloc(dev)) == -ENOMEM)
134147 && (dev->scsi_host_ptr->can_queue > (64 - AAC_NUM_MGT_FIB))) {
135− dev->init->MaxIoCommands = cpu_to_le32((dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) >> 1);
136− dev->scsi_host_ptr->can_queue = le32_to_cpu(dev->init->MaxIoCommands) - AAC_NUM_MGT_FIB;
148+ max_cmds = (dev->scsi_host_ptr->can_queue+AAC_NUM_MGT_FIB) >> 1;
149+ dev->scsi_host_ptr->can_queue = max_cmds - AAC_NUM_MGT_FIB;
150+ if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE3)
151+ dev->init->r7.max_io_commands = cpu_to_le32(max_cmds);
137152 }
138153 if (i<0)
139154 return -ENOMEM;
@@ -144,7 +159,7 @@ int aac_fib_setup(struct aac_dev * dev) · 4 unmodified lines
144159 (hw_fib_pa - dev->hw_fib_pa));
145160 dev->hw_fib_pa = hw_fib_pa;
146161 memset(dev->hw_fib_va, 0,
147− (dev->max_fib_size + sizeof(struct aac_fib_xporthdr)) *
162+ (dev->max_cmd_size + sizeof(struct aac_fib_xporthdr)) *
148163 (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB));
149164
150165 /* add Xport header */
@@ -170,12 +185,22 @@ int aac_fib_setup(struct aac_dev * dev) · 19 unmodified lines
170185 sema_init(&fibptr->event_wait, 0);
171186 spin_lock_init(&fibptr->event_lock);
172187 hw_fib->header.XferState = cpu_to_le32(0xffffffff);
173− hw_fib->header.SenderSize = cpu_to_le16(dev->max_fib_size);
188+ hw_fib->header.SenderSize =
189+ cpu_to_le16(dev->max_fib_size); /* ?? max_cmd_size */
174190 fibptr->hw_fib_pa = hw_fib_pa;
191+ fibptr->hw_sgl_pa = hw_fib_pa +
192+ offsetof(struct aac_hba_cmd_req, sge[2]);
193+ /*
194+ * one element is for the ptr to the separate sg list,
195+ * second element for 32 byte alignment
196+ */
197+ fibptr->hw_error_pa = hw_fib_pa +
198+ offsetof(struct aac_native_hba, resp.resp_bytes[0]);
199+
175200 hw_fib = (struct hw_fib *)((unsigned char *)hw_fib +
176− dev->max_fib_size + sizeof(struct aac_fib_xporthdr));
201+ dev->max_cmd_size + sizeof(struct aac_fib_xporthdr));
177202 hw_fib_pa = hw_fib_pa +
178− dev->max_fib_size + sizeof(struct aac_fib_xporthdr);
203+ dev->max_cmd_size + sizeof(struct aac_fib_xporthdr);
179204 }
180205
181206 /*
@@ -273,7 +298,8 @@ void aac_fib_free(struct fib *fibptr) · 91 unmodified lines
273298 spin_lock_irqsave(&fibptr->dev->fib_lock, flags);
274299 if (unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
275300 aac_config.fib_timeouts++;
276− if (fibptr->hw_fib_va->header.XferState != 0) {
301+ if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) &&
302+ fibptr->hw_fib_va->header.XferState != 0) {
277303 printk(KERN_WARNING "aac_fib_free, XferState != 0, fibptr = 0x%p, XferState = 0x%x\n",
278304 (void*)fibptr,
279305 le32_to_cpu(fibptr->hw_fib_va->header.XferState));
@@ -501,8 +527,15 @@ int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size, · 221 unmodified lines
501527 * Map the fib into 32bits by using the fib number
502528 */
503529
504− hw_fib->header.SenderFibAddress = cpu_to_le32(((u32)(fibptr - dev->fibs)) << 2);
505− hw_fib->header.Handle = (u32)(fibptr - dev->fibs) + 1;
530+ hw_fib->header.SenderFibAddress =
531+ cpu_to_le32(((u32)(fibptr - dev->fibs)) << 2);
532+
533+ /* use the same shifted value for handle to be compatible
534+ * with the new native hba command handle
535+ */
536+ hw_fib->header.Handle =
537+ cpu_to_le32((((u32)(fibptr - dev->fibs)) << 2) + 1);
538+
506539 /*
507540 * Set FIB state to indicate where it came from and if we want a
508541 * response from the adapter. Also load the command from the
@@ -670,6 +703,82 @@ int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size, · 161 unmodified lines
670703 return 0;
671704 }
672705
706+int aac_hba_send(u8 command, struct fib *fibptr, fib_callback callback,
707+ void *callback_data)
708+{
709+ struct aac_dev *dev = fibptr->dev;
710+ int wait;
711+ unsigned long flags = 0;
712+ unsigned long mflags = 0;
713+
714+ fibptr->flags = (FIB_CONTEXT_FLAG | FIB_CONTEXT_FLAG_NATIVE_HBA);
715+ if (callback) {
716+ wait = 0;
717+ fibptr->callback = callback;
718+ fibptr->callback_data = callback_data;
719+ } else
720+ wait = 1;
721+
722+
723+ if (command == HBA_IU_TYPE_SCSI_CMD_REQ) {
724+ struct aac_hba_cmd_req *hbacmd =
725+ (struct aac_hba_cmd_req *)fibptr->hw_fib_va;
726+
727+ hbacmd->iu_type = command;
728+ /* bit1 of request_id must be 0 */
729+ hbacmd->request_id =
730+ cpu_to_le32((((u32)(fibptr - dev->fibs)) << 2) + 1);
731+ } else
732+ return -EINVAL;
733+
734+
735+ if (wait) {
736+ spin_lock_irqsave(&dev->manage_lock, mflags);
737+ if (dev->management_fib_count >= AAC_NUM_MGT_FIB) {
738+ spin_unlock_irqrestore(&dev->manage_lock, mflags);
739+ return -EBUSY;
740+ }
741+ dev->management_fib_count++;
742+ spin_unlock_irqrestore(&dev->manage_lock, mflags);
743+ spin_lock_irqsave(&fibptr->event_lock, flags);
744+ }
745+
746+ if (aac_adapter_deliver(fibptr) != 0) {
747+ if (wait) {
748+ spin_unlock_irqrestore(&fibptr->event_lock, flags);
749+ spin_lock_irqsave(&dev->manage_lock, mflags);
750+ dev->management_fib_count--;
751+ spin_unlock_irqrestore(&dev->manage_lock, mflags);
752+ }
753+ return -EBUSY;
754+ }
755+ FIB_COUNTER_INCREMENT(aac_config.NativeSent);
756+
757+ if (wait) {
758+ spin_unlock_irqrestore(&fibptr->event_lock, flags);
759+ /* Only set for first known interruptable command */
760+ if (down_interruptible(&fibptr->event_wait)) {
761+ fibptr->done = 2;
762+ up(&fibptr->event_wait);
763+ }
764+ spin_lock_irqsave(&fibptr->event_lock, flags);
765+ if ((fibptr->done == 0) || (fibptr->done == 2)) {
766+ fibptr->done = 2; /* Tell interrupt we aborted */
767+ spin_unlock_irqrestore(&fibptr->event_lock, flags);
768+ return -ERESTARTSYS;
769+ }
770+ spin_unlock_irqrestore(&fibptr->event_lock, flags);
771+ WARN_ON(fibptr->done == 0);
772+
773+ if (unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
774+ return -ETIMEDOUT;
775+
776+ return 0;
777+ }
778+
779+ return -EINPROGRESS;
780+}
781+
673782 /**
674783 * aac_consumer_get - get the top of the queue
675784 * @dev: Adapter
@@ -761,7 +870,8 @@ int aac_fib_adapter_complete(struct fib *fibptr, unsigned short size) · 85 unmodified lines
761870 unsigned long qflags;
762871
763872 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
764− dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
873+ dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
874+ dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) {
765875 kfree(hw_fib);
766876 return 0;
767877 }
@@ -827,11 +937,17 @@ int aac_fib_complete(struct fib *fibptr) · 59 unmodified lines
827937 {
828938 struct hw_fib * hw_fib = fibptr->hw_fib_va;
829939
940+ if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) {
941+ fib_dealloc(fibptr);
942+ return 0;
943+ }
944+
830945 /*
831− * Check for a fib which has already been completed
946+ * Check for a fib which has already been completed or with a
947+ * status wait timeout
832948 */
833949
834− if (hw_fib->header.XferState == 0)
950+ if (hw_fib->header.XferState == 0 || fibptr->done == 2)
835951 return 0;
836952 /*
837953 * If we plan to do anything check the structure type first.
@@ -984,20 +1100,9 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr) · 146 unmodified lines
9841100 lun = (container >> 16) & 0xFF;
9851101 container = (u32)-1;
9861102 channel = aac_phys_to_logical(channel);
987− device_config_needed =
988− (((__le32 *)aifcmd->data)[0] ==
989− cpu_to_le32(AifRawDeviceRemove)) ? DELETE : ADD;
990−
991− if (device_config_needed == ADD) {
992− device = scsi_device_lookup(
993− dev->scsi_host_ptr,
994− channel, id, lun);
995− if (device) {
996− scsi_remove_device(device);
997− scsi_device_put(device);
998− }
999− }
1103+ device_config_needed = DELETE;
10001104 break;
1105+
10011106 /*
10021107 * Morph or Expand complete
10031108 */
@@ -1351,7 +1456,7 @@ retry_next: · 347 unmodified lines
13511456 }
13521457 }
13531458
1354−static int _aac_reset_adapter(struct aac_dev *aac, int forced)
1459+static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
13551460 {
13561461 int index, quirks;
13571462 int retval;
@@ -1360,6 +1465,7 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced) · 2 unmodified lines
13601465 struct scsi_cmnd *command;
13611466 struct scsi_cmnd *command_list;
13621467 int jafo = 0;
1468+ int bled;
13631469
13641470 /*
13651471 * Assumptions:
@@ -1384,7 +1490,8 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced) · 18 unmodified lines
13841490 * If a positive health, means in a known DEAD PANIC
13851491 * state and the adapter could be reset to `try again'.
13861492 */
1387− retval = aac_adapter_restart(aac, forced ? 0 : aac_adapter_check_health(aac));
1493+ bled = forced ? 0 : aac_adapter_check_health(aac);
1494+ retval = aac_adapter_restart(aac, bled, reset_type);
13881495
13891496 if (retval)
13901497 goto out;
@@ -1494,11 +1601,12 @@ out: · 103 unmodified lines
14941601 return retval;
14951602 }
14961603
1497−int aac_reset_adapter(struct aac_dev * aac, int forced)
1604+int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
14981605 {
14991606 unsigned long flagv = 0;
15001607 int retval;
15011608 struct Scsi_Host * host;
1609+ int bled;
15021610
15031611 if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0)
15041612 return -EBUSY;
@@ -1547,7 +1655,9 @@ int aac_reset_adapter(struct aac_dev * aac, int forced) · 42 unmodified lines
15471655 if (forced < 2)
15481656 aac_send_shutdown(aac);
15491657 spin_lock_irqsave(host->host_lock, flagv);
1550− retval = _aac_reset_adapter(aac, forced ? forced : ((aac_check_reset != 0) && (aac_check_reset != 1)));
1658+ bled = forced ? forced :
1659+ (aac_check_reset != 0 && aac_check_reset != 1);
1660+ retval = _aac_reset_adapter(aac, bled, reset_type);
15511661 spin_unlock_irqrestore(host->host_lock, flagv);
15521662
15531663 if ((forced < 2) && (retval == -ENODEV)) {
@@ -1593,6 +1703,7 @@ int aac_check_health(struct aac_dev * aac) · 39 unmodified lines
15931703 unsigned long time_now, flagv = 0;
15941704 struct list_head * entry;
15951705 struct Scsi_Host * host;
1706+ int bled;
15961707
15971708 /* Extending the scope of fib_lock slightly to protect aac->in_reset */
15981709 if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0)
@@ -1710,7 +1821,8 @@ int aac_check_health(struct aac_dev * aac) · 111 unmodified lines
17101821 host = aac->scsi_host_ptr;
17111822 if (aac->thread->pid != current->pid)
17121823 spin_lock_irqsave(host->host_lock, flagv);
1713− BlinkLED = _aac_reset_adapter(aac, aac_check_reset != 1);
1824+ bled = aac_check_reset != 1 ? 1 : 0;
1825+ _aac_reset_adapter(aac, bled, IOP_HWSOFT_RESET);
17141826 if (aac->thread->pid != current->pid)
17151827 spin_unlock_irqrestore(host->host_lock, flagv);
17161828 return BlinkLED;
@@ -1721,6 +1833,552 @@ out: · 4 unmodified lines
17211833 }
17221834
17231835
1836+static void aac_resolve_luns(struct aac_dev *dev)
1837+{
1838+ int bus, target, channel;
1839+ struct scsi_device *sdev;
1840+ u8 devtype;
1841+ u8 new_devtype;
1842+
1843+ for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
1844+ for (target = 0; target < AAC_MAX_TARGETS; target++) {
1845+
1846+ if (aac_phys_to_logical(bus) == ENCLOSURE_CHANNEL)
1847+ continue;
1848+
1849+ if (bus == CONTAINER_CHANNEL)
1850+ channel = CONTAINER_CHANNEL;
1851+ else
1852+ channel = aac_phys_to_logical(bus);
1853+
1854+ devtype = dev->hba_map[bus][target].devtype;
1855+ new_devtype = dev->hba_map[bus][target].new_devtype;
1856+
1857+ sdev = scsi_device_lookup(dev->scsi_host_ptr, channel,
1858+ target, 0);
1859+
1860+ if (!sdev && devtype)
1861+ scsi_add_device(dev->scsi_host_ptr, channel,
1862+ target, 0);
1863+ else if (sdev && new_devtype != devtype)
1864+ scsi_remove_device(sdev);
1865+ else if (sdev && new_devtype == devtype)
1866+ scsi_rescan_device(&sdev->sdev_gendev);
1867+
1868+ if (sdev)
1869+ scsi_device_put(sdev);
1870+
1871+ dev->hba_map[bus][target].devtype = new_devtype;
1872+ }
1873+ }
1874+}
1875+
1876+/**
1877+ * aac_handle_sa_aif Handle a message from the firmware
1878+ * @dev: Which adapter this fib is from
1879+ * @fibptr: Pointer to fibptr from adapter
1880+ *
1881+ * This routine handles a driver notify fib from the adapter and
1882+ * dispatches it to the appropriate routine for handling.
1883+ */
1884+static void aac_handle_sa_aif(struct aac_dev *dev, struct fib *fibptr)
1885+{
1886+ int i, bus, target, container, rcode = 0;
1887+ u32 events = 0;
1888+ struct fib *fib;
1889+ struct scsi_device *sdev;
1890+
1891+ if (fibptr->hbacmd_size & SA_AIF_HOTPLUG)
1892+ events = SA_AIF_HOTPLUG;
1893+ else if (fibptr->hbacmd_size & SA_AIF_HARDWARE)
1894+ events = SA_AIF_HARDWARE;
1895+ else if (fibptr->hbacmd_size & SA_AIF_PDEV_CHANGE)
1896+ events = SA_AIF_PDEV_CHANGE;
1897+ else if (fibptr->hbacmd_size & SA_AIF_LDEV_CHANGE)
1898+ events = SA_AIF_LDEV_CHANGE;
1899+ else if (fibptr->hbacmd_size & SA_AIF_BPSTAT_CHANGE)
1900+ events = SA_AIF_BPSTAT_CHANGE;
1901+ else if (fibptr->hbacmd_size & SA_AIF_BPCFG_CHANGE)
1902+ events = SA_AIF_BPCFG_CHANGE;
1903+
1904+ switch (events) {
1905+ case SA_AIF_HOTPLUG:
1906+ case SA_AIF_HARDWARE:
1907+ case SA_AIF_PDEV_CHANGE:
1908+ case SA_AIF_LDEV_CHANGE:
1909+ case SA_AIF_BPCFG_CHANGE:
1910+
1911+ fib = aac_fib_alloc(dev);
1912+ if (!fib) {
1913+ pr_err("aac_handle_sa_aif: out of memory\n");
1914+ return;
1915+ }
1916+ for (bus = 0; bus < AAC_MAX_BUSES; bus++)
1917+ for (target = 0; target < AAC_MAX_TARGETS; target++)
1918+ dev->hba_map[bus][target].new_devtype = 0;
1919+
1920+ rcode = aac_report_phys_luns(dev, fib, AAC_RESCAN);
1921+
1922+ if (rcode != -ERESTARTSYS)
1923+ aac_fib_free(fib);
1924+
1925+ aac_resolve_luns(dev);
1926+
1927+ if (events == SA_AIF_LDEV_CHANGE ||
1928+ events == SA_AIF_BPCFG_CHANGE) {
1929+ aac_get_containers(dev);
1930+ for (container = 0; container <
1931+ dev->maximum_num_containers; ++container) {
1932+ sdev = scsi_device_lookup(dev->scsi_host_ptr,
1933+ CONTAINER_CHANNEL,
1934+ container, 0);
1935+ if (dev->fsa_dev[container].valid && !sdev) {
1936+ scsi_add_device(dev->scsi_host_ptr,
1937+ CONTAINER_CHANNEL,
1938+ container, 0);
1939+ } else if (!dev->fsa_dev[container].valid &&
1940+ sdev) {
1941+ scsi_remove_device(sdev);
1942+ scsi_device_put(sdev);
1943+ } else if (sdev) {
1944+ scsi_rescan_device(&sdev->sdev_gendev);
1945+ scsi_device_put(sdev);
1946+ }
1947+ }
1948+ }
1949+ break;
1950+
1951+ case SA_AIF_BPSTAT_CHANGE:
1952+ /* currently do nothing */
1953+ break;
1954+ }
1955+
1956+ for (i = 1; i <= 10; ++i) {
1957+ events = src_readl(dev, MUnit.IDR);
1958+ if (events & (1<<23)) {
1959+ pr_warn(" AIF not cleared by firmware - %d/%d)\n",
1960+ i, 10);
1961+ ssleep(1);
1962+ }
1963+ }
1964+}
1965+
1966+static int get_fib_count(struct aac_dev *dev)
1967+{
1968+ unsigned int num = 0;
1969+ struct list_head *entry;
1970+ unsigned long flagv;
1971+
1972+ /*
1973+ * Warning: no sleep allowed while
1974+ * holding spinlock. We take the estimate
1975+ * and pre-allocate a set of fibs outside the
1976+ * lock.
1977+ */
1978+ num = le32_to_cpu(dev->init->r7.adapter_fibs_size)
1979+ / sizeof(struct hw_fib); /* some extra */
1980+ spin_lock_irqsave(&dev->fib_lock, flagv);
1981+ entry = dev->fib_list.next;
1982+ while (entry != &dev->fib_list) {
1983+ entry = entry->next;
1984+ ++num;
1985+ }
1986+ spin_unlock_irqrestore(&dev->fib_lock, flagv);
1987+
1988+ return num;
1989+}
1990+
1991+static int fillup_pools(struct aac_dev *dev, struct hw_fib **hw_fib_pool,
1992+ struct fib **fib_pool,
1993+ unsigned int num)
1994+{
1995+ struct hw_fib **hw_fib_p;
1996+ struct fib **fib_p;
1997+ int rcode = 1;
1998+
1999+ hw_fib_p = hw_fib_pool;
2000+ fib_p = fib_pool;
2001+ while (hw_fib_p < &hw_fib_pool[num]) {
2002+ *(hw_fib_p) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL);
2003+ if (!(*(hw_fib_p++))) {
2004+ --hw_fib_p;
2005+ break;
2006+ }
2007+
2008+ *(fib_p) = kmalloc(sizeof(struct fib), GFP_KERNEL);
2009+ if (!(*(fib_p++))) {
2010+ kfree(*(--hw_fib_p));
2011+ break;
2012+ }
2013+ }
2014+
2015+ num = hw_fib_p - hw_fib_pool;
2016+ if (!num)
2017+ rcode = 0;
2018+
2019+ return rcode;
2020+}
2021+
2022+static void wakeup_fibctx_threads(struct aac_dev *dev,
2023+ struct hw_fib **hw_fib_pool,
2024+ struct fib **fib_pool,
2025+ struct fib *fib,
2026+ struct hw_fib *hw_fib,
2027+ unsigned int num)
2028+{
2029+ unsigned long flagv;
2030+ struct list_head *entry;
2031+ struct hw_fib **hw_fib_p;
2032+ struct fib **fib_p;
2033+ u32 time_now, time_last;
2034+ struct hw_fib *hw_newfib;
2035+ struct fib *newfib;
2036+ struct aac_fib_context *fibctx;
2037+
2038+ time_now = jiffies/HZ;
2039+ spin_lock_irqsave(&dev->fib_lock, flagv);
2040+ entry = dev->fib_list.next;
2041+ /*
2042+ * For each Context that is on the
2043+ * fibctxList, make a copy of the
2044+ * fib, and then set the event to wake up the
2045+ * thread that is waiting for it.
2046+ */
2047+
2048+ hw_fib_p = hw_fib_pool;
2049+ fib_p = fib_pool;
2050+ while (entry != &dev->fib_list) {
2051+ /*
2052+ * Extract the fibctx
2053+ */
2054+ fibctx = list_entry(entry, struct aac_fib_context,
2055+ next);
2056+ /*
2057+ * Check if the queue is getting
2058+ * backlogged
2059+ */
2060+ if (fibctx->count > 20) {
2061+ /*
2062+ * It's *not* jiffies folks,
2063+ * but jiffies / HZ so do not
2064+ * panic ...
2065+ */
2066+ time_last = fibctx->jiffies;
2067+ /*
2068+ * Has it been > 2 minutes
2069+ * since the last read off
2070+ * the queue?
2071+ */
2072+ if ((time_now - time_last) > aif_timeout) {
2073+ entry = entry->next;
2074+ aac_close_fib_context(dev, fibctx);
2075+ continue;
2076+ }
2077+ }
2078+ /*
2079+ * Warning: no sleep allowed while
2080+ * holding spinlock
2081+ */
2082+ if (hw_fib_p >= &hw_fib_pool[num]) {
2083+ pr_warn("aifd: didn't allocate NewFib\n");
2084+ entry = entry->next;
2085+ continue;
2086+ }
2087+
2088+ hw_newfib = *hw_fib_p;
2089+ *(hw_fib_p++) = NULL;
2090+ newfib = *fib_p;
2091+ *(fib_p++) = NULL;
2092+ /*
2093+ * Make the copy of the FIB
2094+ */
2095+ memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib));
2096+ memcpy(newfib, fib, sizeof(struct fib));
2097+ newfib->hw_fib_va = hw_newfib;
2098+ /*
2099+ * Put the FIB onto the
2100+ * fibctx's fibs
2101+ */
2102+ list_add_tail(&newfib->fiblink, &fibctx->fib_list);
2103+ fibctx->count++;
2104+ /*
2105+ * Set the event to wake up the
2106+ * thread that is waiting.
2107+ */
2108+ up(&fibctx->wait_sem);
2109+
2110+ entry = entry->next;
2111+ }
2112+ /*
2113+ * Set the status of this FIB
2114+ */
2115+ *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
2116+ aac_fib_adapter_complete(fib, sizeof(u32));
2117+ spin_unlock_irqrestore(&dev->fib_lock, flagv);
2118+
2119+}
2120+
2121+static void aac_process_events(struct aac_dev *dev)
2122+{
2123+ struct hw_fib *hw_fib;
2124+ struct fib *fib;
2125+ unsigned long flags;
2126+ spinlock_t *t_lock;
2127+ unsigned int rcode;
2128+
2129+ t_lock = dev->queues->queue[HostNormCmdQueue].lock;
2130+ spin_lock_irqsave(t_lock, flags);
2131+
2132+ while (!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) {
2133+ struct list_head *entry;
2134+ struct aac_aifcmd *aifcmd;
2135+ unsigned int num;
2136+ struct hw_fib **hw_fib_pool, **hw_fib_p;
2137+ struct fib **fib_pool, **fib_p;
2138+
2139+ set_current_state(TASK_RUNNING);
2140+
2141+ entry = dev->queues->queue[HostNormCmdQueue].cmdq.next;
2142+ list_del(entry);
2143+
2144+ t_lock = dev->queues->queue[HostNormCmdQueue].lock;
2145+ spin_unlock_irqrestore(t_lock, flags);
2146+
2147+ fib = list_entry(entry, struct fib, fiblink);
2148+ hw_fib = fib->hw_fib_va;
2149+ if (dev->sa_firmware) {
2150+ /* Thor AIF */
2151+ aac_handle_sa_aif(dev, fib);
2152+ aac_fib_adapter_complete(fib, (u16)sizeof(u32));
2153+ continue;
2154+ }
2155+ /*
2156+ * We will process the FIB here or pass it to a
2157+ * worker thread that is TBD. We Really can't
2158+ * do anything at this point since we don't have
2159+ * anything defined for this thread to do.
2160+ */
2161+ memset(fib, 0, sizeof(struct fib));
2162+ fib->type = FSAFS_NTC_FIB_CONTEXT;
2163+ fib->size = sizeof(struct fib);
2164+ fib->hw_fib_va = hw_fib;
2165+ fib->data = hw_fib->data;
2166+ fib->dev = dev;
2167+ /*
2168+ * We only handle AifRequest fibs from the adapter.
2169+ */
2170+
2171+ aifcmd = (struct aac_aifcmd *) hw_fib->data;
2172+ if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
2173+ /* Handle Driver Notify Events */
2174+ aac_handle_aif(dev, fib);
2175+ *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
2176+ aac_fib_adapter_complete(fib, (u16)sizeof(u32));
2177+ goto free_fib;
2178+ }
2179+ /*
2180+ * The u32 here is important and intended. We are using
2181+ * 32bit wrapping time to fit the adapter field
2182+ */
2183+
2184+ /* Sniff events */
2185+ if (aifcmd->command == cpu_to_le32(AifCmdEventNotify)
2186+ || aifcmd->command == cpu_to_le32(AifCmdJobProgress)) {
2187+ aac_handle_aif(dev, fib);
2188+ }
2189+
2190+ /*
2191+ * get number of fibs to process
2192+ */
2193+ num = get_fib_count(dev);
2194+ if (!num)
2195+ goto free_fib;
2196+
2197+ hw_fib_pool = kmalloc_array(num, sizeof(struct hw_fib *),
2198+ GFP_KERNEL);
2199+ if (!hw_fib_pool)
2200+ goto free_fib;
2201+
2202+ fib_pool = kmalloc_array(num, sizeof(struct fib *), GFP_KERNEL);
2203+ if (!fib_pool)
2204+ goto free_hw_fib_pool;
2205+
2206+ /*
2207+ * Fill up fib pointer pools with actual fibs
2208+ * and hw_fibs
2209+ */
2210+ rcode = fillup_pools(dev, hw_fib_pool, fib_pool, num);
2211+ if (!rcode)
2212+ goto free_mem;
2213+
2214+ /*
2215+ * wakeup the thread that is waiting for
2216+ * the response from fw (ioctl)
2217+ */
2218+ wakeup_fibctx_threads(dev, hw_fib_pool, fib_pool,
2219+ fib, hw_fib, num);
2220+
2221+free_mem:
2222+ /* Free up the remaining resources */
2223+ hw_fib_p = hw_fib_pool;
2224+ fib_p = fib_pool;
2225+ while (hw_fib_p < &hw_fib_pool[num]) {
2226+ kfree(*hw_fib_p);
2227+ kfree(*fib_p);
2228+ ++fib_p;
2229+ ++hw_fib_p;
2230+ }
2231+ kfree(fib_pool);
2232+free_hw_fib_pool:
2233+ kfree(hw_fib_pool);
2234+free_fib:
2235+ kfree(fib);
2236+ t_lock = dev->queues->queue[HostNormCmdQueue].lock;
2237+ spin_lock_irqsave(t_lock, flags);
2238+ }
2239+ /*
2240+ * There are no more AIF's
2241+ */
2242+ t_lock = dev->queues->queue[HostNormCmdQueue].lock;
2243+ spin_unlock_irqrestore(t_lock, flags);
2244+}
2245+
2246+static int aac_send_wellness_command(struct aac_dev *dev, char *wellness_str,
2247+ u32 datasize)
2248+{
2249+ struct aac_srb *srbcmd;
2250+ struct sgmap64 *sg64;
2251+ dma_addr_t addr;
2252+ char *dma_buf;
2253+ struct fib *fibptr;
2254+ int ret = -ENOMEM;
2255+ u32 vbus, vid;
2256+
2257+ fibptr = aac_fib_alloc(dev);
2258+ if (!fibptr)
2259+ goto out;
2260+
2261+ dma_buf = pci_alloc_consistent(dev->pdev, datasize, &addr);
2262+ if (!dma_buf)
2263+ goto fib_free_out;
2264+
2265+ aac_fib_init(fibptr);
2266+
2267+ vbus = (u32)le16_to_cpu(dev->supplement_adapter_info.VirtDeviceBus);
2268+ vid = (u32)le16_to_cpu(dev->supplement_adapter_info.VirtDeviceTarget);
2269+
2270+ srbcmd = (struct aac_srb *)fib_data(fibptr);
2271+
2272+ srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
2273+ srbcmd->channel = cpu_to_le32(vbus);
2274+ srbcmd->id = cpu_to_le32(vid);
2275+ srbcmd->lun = 0;
2276+ srbcmd->flags = cpu_to_le32(SRB_DataOut);
2277+ srbcmd->timeout = cpu_to_le32(10);
2278+ srbcmd->retry_limit = 0;
2279+ srbcmd->cdb_size = cpu_to_le32(12);
2280+ srbcmd->count = cpu_to_le32(datasize);
2281+
2282+ memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2283+ srbcmd->cdb[0] = BMIC_OUT;
2284+ srbcmd->cdb[6] = WRITE_HOST_WELLNESS;
2285+ memcpy(dma_buf, (char *)wellness_str, datasize);
2286+
2287+ sg64 = (struct sgmap64 *)&srbcmd->sg;
2288+ sg64->count = cpu_to_le32(1);
2289+ sg64->sg[0].addr[1] = cpu_to_le32((u32)(((addr) >> 16) >> 16));
2290+ sg64->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2291+ sg64->sg[0].count = cpu_to_le32(datasize);
2292+
2293+ ret = aac_fib_send(ScsiPortCommand64, fibptr, sizeof(struct aac_srb),
2294+ FsaNormal, 1, 1, NULL, NULL);
2295+
2296+ pci_free_consistent(dev->pdev, datasize, (void *)dma_buf, addr);
2297+
2298+ /*
2299+ * Do not set XferState to zero unless
2300+ * receives a response from F/W
2301+ */
2302+ if (ret >= 0)
2303+ aac_fib_complete(fibptr);
2304+
2305+ /*
2306+ * FIB should be freed only after
2307+ * getting the response from the F/W
2308+ */
2309+ if (ret != -ERESTARTSYS)
2310+ goto fib_free_out;
2311+
2312+out:
2313+ return ret;
2314+fib_free_out:
2315+ aac_fib_free(fibptr);
2316+ goto out;
2317+}
2318+
2319+int aac_send_safw_hostttime(struct aac_dev *dev, struct timeval *now)
2320+{
2321+ struct tm cur_tm;
2322+ char wellness_str[] = "<HW>TD\010\0\0\0\0\0\0\0\0\0DW\0\0ZZ";
2323+ u32 datasize = sizeof(wellness_str);
2324+ unsigned long local_time;
2325+ int ret = -ENODEV;
2326+
2327+ if (!dev->sa_firmware)
2328+ goto out;
2329+
2330+ local_time = (u32)(now->tv_sec - (sys_tz.tz_minuteswest * 60));
2331+ time_to_tm(local_time, 0, &cur_tm);
2332+ cur_tm.tm_mon += 1;
2333+ cur_tm.tm_year += 1900;
2334+ wellness_str[8] = bin2bcd(cur_tm.tm_hour);
2335+ wellness_str[9] = bin2bcd(cur_tm.tm_min);
2336+ wellness_str[10] = bin2bcd(cur_tm.tm_sec);
2337+ wellness_str[12] = bin2bcd(cur_tm.tm_mon);
2338+ wellness_str[13] = bin2bcd(cur_tm.tm_mday);
2339+ wellness_str[14] = bin2bcd(cur_tm.tm_year / 100);
2340+ wellness_str[15] = bin2bcd(cur_tm.tm_year % 100);
2341+
2342+ ret = aac_send_wellness_command(dev, wellness_str, datasize);
2343+
2344+out:
2345+ return ret;
2346+}
2347+
2348+int aac_send_hosttime(struct aac_dev *dev, struct timeval *now)
2349+{
2350+ int ret = -ENOMEM;
2351+ struct fib *fibptr;
2352+ __le32 *info;
2353+
2354+ fibptr = aac_fib_alloc(dev);
2355+ if (!fibptr)
2356+ goto out;
2357+
2358+ aac_fib_init(fibptr);
2359+ info = (__le32 *)fib_data(fibptr);
2360+ *info = cpu_to_le32(now->tv_sec);
2361+ ret = aac_fib_send(SendHostTime, fibptr, sizeof(*info), FsaNormal,
2362+ 1, 1, NULL, NULL);
2363+
2364+ /*
2365+ * Do not set XferState to zero unless
2366+ * receives a response from F/W
2367+ */
2368+ if (ret >= 0)
2369+ aac_fib_complete(fibptr);
2370+
2371+ /*
2372+ * FIB should be freed only after
2373+ * getting the response from the F/W
2374+ */
2375+ if (ret != -ERESTARTSYS)
2376+ aac_fib_free(fibptr);
2377+
2378+out:
2379+ return ret;
2380+}
2381+
17242382 /**
17252383 * aac_command_thread - command processing thread
17262384 * @dev: Adapter to monitor
@@ -1734,10 +2392,6 @@ out: · 7 unmodified lines
17342392 int aac_command_thread(void *data)
17352393 {
17362394 struct aac_dev *dev = data;
1737− struct hw_fib *hw_fib, *hw_newfib;
1738− struct fib *fib, *newfib;
1739− struct aac_fib_context *fibctx;
1740− unsigned long flags;
17412395 DECLARE_WAITQUEUE(wait, current);
17422396 unsigned long next_jiffies = jiffies + HZ;
17432397 unsigned long next_check_jiffies = next_jiffies;
@@ -1757,196 +2411,8 @@ int aac_command_thread(void *data) · 13 unmodified lines
17572411 set_current_state(TASK_INTERRUPTIBLE);
17582412 dprintk ((KERN_INFO "aac_command_thread start\n"));
17592413 while (1) {
1760− spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
1761− while(!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) {
1762− struct list_head *entry;
1763− struct aac_aifcmd * aifcmd;
1764−
1765− set_current_state(TASK_RUNNING);
17662414
1767− entry = dev->queues->queue[HostNormCmdQueue].cmdq.next;
1768− list_del(entry);
1769−
1770− spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
1771− fib = list_entry(entry, struct fib, fiblink);
1772− /*
1773− * We will process the FIB here or pass it to a
1774− * worker thread that is TBD. We Really can't
1775− * do anything at this point since we don't have
1776− * anything defined for this thread to do.
1777− */
1778− hw_fib = fib->hw_fib_va;
1779− memset(fib, 0, sizeof(struct fib));
1780− fib->type = FSAFS_NTC_FIB_CONTEXT;
1781− fib->size = sizeof(struct fib);
1782− fib->hw_fib_va = hw_fib;
1783− fib->data = hw_fib->data;
1784− fib->dev = dev;
1785− /*
1786− * We only handle AifRequest fibs from the adapter.
1787− */
1788− aifcmd = (struct aac_aifcmd *) hw_fib->data;
1789− if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
1790− /* Handle Driver Notify Events */
1791− aac_handle_aif(dev, fib);
1792− *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
1793− aac_fib_adapter_complete(fib, (u16)sizeof(u32));
1794− } else {
1795− /* The u32 here is important and intended. We are using
1796− 32bit wrapping time to fit the adapter field */
1797−
1798− u32 time_now, time_last;
1799− unsigned long flagv;
1800− unsigned num;
1801− struct hw_fib ** hw_fib_pool, ** hw_fib_p;
1802− struct fib ** fib_pool, ** fib_p;
1803−
1804− /* Sniff events */
1805− if ((aifcmd->command ==
1806− cpu_to_le32(AifCmdEventNotify)) ||
1807− (aifcmd->command ==
1808− cpu_to_le32(AifCmdJobProgress))) {
1809− aac_handle_aif(dev, fib);
1810− }
1811−
1812− time_now = jiffies/HZ;
1813−
1814− /*
1815− * Warning: no sleep allowed while
1816− * holding spinlock. We take the estimate
1817− * and pre-allocate a set of fibs outside the
1818− * lock.
1819− */
1820− num = le32_to_cpu(dev->init->AdapterFibsSize)
1821− / sizeof(struct hw_fib); /* some extra */
1822− spin_lock_irqsave(&dev->fib_lock, flagv);
1823− entry = dev->fib_list.next;
1824− while (entry != &dev->fib_list) {
1825− entry = entry->next;
1826− ++num;
1827− }
1828− spin_unlock_irqrestore(&dev->fib_lock, flagv);
1829− hw_fib_pool = NULL;
1830− fib_pool = NULL;
1831− if (num
1832− && ((hw_fib_pool = kmalloc(sizeof(struct hw_fib *) * num, GFP_KERNEL)))
1833− && ((fib_pool = kmalloc(sizeof(struct fib *) * num, GFP_KERNEL)))) {
1834− hw_fib_p = hw_fib_pool;
1835− fib_p = fib_pool;
1836− while (hw_fib_p < &hw_fib_pool[num]) {
1837− if (!(*(hw_fib_p++) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL))) {
1838− --hw_fib_p;
1839− break;
1840− }
1841− if (!(*(fib_p++) = kmalloc(sizeof(struct fib), GFP_KERNEL))) {
1842− kfree(*(--hw_fib_p));
1843− break;
1844− }
1845− }
1846− if ((num = hw_fib_p - hw_fib_pool) == 0) {
1847− kfree(fib_pool);
1848− fib_pool = NULL;
1849− kfree(hw_fib_pool);
1850− hw_fib_pool = NULL;
1851− }
1852− } else {
1853− kfree(hw_fib_pool);
1854− hw_fib_pool = NULL;
1855− }
1856− spin_lock_irqsave(&dev->fib_lock, flagv);
1857− entry = dev->fib_list.next;
1858− /*
1859− * For each Context that is on the
1860− * fibctxList, make a copy of the
1861− * fib, and then set the event to wake up the
1862− * thread that is waiting for it.
1863− */
1864− hw_fib_p = hw_fib_pool;
1865− fib_p = fib_pool;
1866− while (entry != &dev->fib_list) {
1867− /*
1868− * Extract the fibctx
1869− */
1870− fibctx = list_entry(entry, struct aac_fib_context, next);
1871− /*
1872− * Check if the queue is getting
1873− * backlogged
1874− */
1875− if (fibctx->count > 20)
1876− {
1877− /*
1878− * It's *not* jiffies folks,
1879− * but jiffies / HZ so do not
1880− * panic ...
1881− */
1882− time_last = fibctx->jiffies;
1883− /*
1884− * Has it been > 2 minutes
1885− * since the last read off
1886− * the queue?
1887− */
1888− if ((time_now - time_last) > aif_timeout) {
1889− entry = entry->next;
1890− aac_close_fib_context(dev, fibctx);
1891− continue;
1892− }
1893− }
1894− /*
1895− * Warning: no sleep allowed while
1896− * holding spinlock
1897− */
1898− if (hw_fib_p < &hw_fib_pool[num]) {
1899− hw_newfib = *hw_fib_p;
1900− *(hw_fib_p++) = NULL;
1901− newfib = *fib_p;
1902− *(fib_p++) = NULL;
1903− /*
1904− * Make the copy of the FIB
1905− */
1906− memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib));
1907− memcpy(newfib, fib, sizeof(struct fib));
1908− newfib->hw_fib_va = hw_newfib;
1909− /*
1910− * Put the FIB onto the
1911− * fibctx's fibs
1912− */
1913− list_add_tail(&newfib->fiblink, &fibctx->fib_list);
1914− fibctx->count++;
1915− /*
1916− * Set the event to wake up the
1917− * thread that is waiting.
1918− */
1919− up(&fibctx->wait_sem);
1920− } else {
1921− printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
1922− }
1923− entry = entry->next;
1924− }
1925− /*
1926− * Set the status of this FIB
1927− */
1928− *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
1929− aac_fib_adapter_complete(fib, sizeof(u32));
1930− spin_unlock_irqrestore(&dev->fib_lock, flagv);
1931− /* Free up the remaining resources */
1932− hw_fib_p = hw_fib_pool;
1933− fib_p = fib_pool;
1934− while (hw_fib_p < &hw_fib_pool[num]) {
1935− kfree(*hw_fib_p);
1936− kfree(*fib_p);
1937− ++fib_p;
1938− ++hw_fib_p;
1939− }
1940− kfree(hw_fib_pool);
1941− kfree(fib_pool);
1942− }
1943− kfree(fib);
1944− spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
1945− }
1946− /*
1947− * There are no more AIF's
1948− */
1949− spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
2415+ aac_process_events(dev);
19502416
19512417 /*
19522418 * Background activity
@@ -1968,7 +2434,7 @@ int aac_command_thread(void *data) · 15 unmodified lines
19682434
19692435 /* Don't even try to talk to adapter if its sick */
19702436 ret = aac_check_health(dev);
1971− if (!ret && !dev->queues)
2437+ if (!dev->queues)
19722438 break;
19732439 next_check_jiffies = jiffies
19742440 + ((long)(unsigned)check_interval)
@@ -1981,36 +2447,16 @@ int aac_command_thread(void *data) · 6 unmodified lines
19812447 difference = (((1000000 - now.tv_usec) * HZ)
19822448 + 500000) / 1000000;
19832449 else if (ret == 0) {
1984− struct fib *fibptr;
1985−
1986− if ((fibptr = aac_fib_alloc(dev))) {
1987− int status;
1988− __le32 *info;
1989−
1990− aac_fib_init(fibptr);
1991−
1992− info = (__le32 *) fib_data(fibptr);
1993− if (now.tv_usec > 500000)
1994− ++now.tv_sec;
1995−
1996− *info = cpu_to_le32(now.tv_sec);
1997−
1998− status = aac_fib_send(SendHostTime,
1999− fibptr,
2000− sizeof(*info),
2001− FsaNormal,
2002− 1, 1,
2003− NULL,
2004− NULL);
2005− /* Do not set XferState to zero unless
2006− * receives a response from F/W */
2007− if (status >= 0)
2008− aac_fib_complete(fibptr);
2009− /* FIB should be freed only after
2010− * getting the response from the F/W */
2011− if (status != -ERESTARTSYS)
2012− aac_fib_free(fibptr);
2013− }
2450+
2451+ if (now.tv_usec > 500000)
2452+ ++now.tv_sec;
2453+
2454+ if (dev->sa_firmware)
2455+ ret =
2456+ aac_send_safw_hostttime(dev, &now);
2457+ else
2458+ ret = aac_send_hosttime(dev, &now);
2459+
20142460 difference = (long)(unsigned)update_interval*HZ;
20152461 } else {
20162462 /* retry shortly */
drivers/scsi/aacraid/dpcsup.c+103−56
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -122,7 +123,6 @@ unsigned int aac_response_normal(struct aac_queue * q) · 109 unmodified lines
122123 * NOTE: we cannot touch the fib after this
123124 * call, because it may have been deallocated.
124125 */
125− fib->flags &= FIB_CONTEXT_FLAG_FASTRESP;
126126 fib->callback(fib->callback_data, fib);
127127 } else {
128128 unsigned long flagv;
@@ -251,8 +251,9 @@ static void aac_aif_callback(void *context, struct fib * fibptr) · 122 unmodified lines
251251 BUG_ON(fibptr == NULL);
252252 dev = fibptr->dev;
253253
254− if (fibptr->hw_fib_va->header.XferState &
255− cpu_to_le32(NoMoreAifDataAvailable)) {
254+ if ((fibptr->hw_fib_va->header.XferState &
255+ cpu_to_le32(NoMoreAifDataAvailable)) ||
256+ dev->sa_firmware) {
256257 aac_fib_complete(fibptr);
257258 aac_fib_free(fibptr);
258259 return;
@@ -282,8 +283,8 @@ static void aac_aif_callback(void *context, struct fib * fibptr) · 23 unmodified lines
282283 * know there is a response on our normal priority queue. We will pull off
283284 * all QE there are and wake up all the waiters before exiting.
284285 */
285−unsigned int aac_intr_normal(struct aac_dev *dev, u32 index,
286− int isAif, int isFastResponse, struct hw_fib *aif_fib)
286+unsigned int aac_intr_normal(struct aac_dev *dev, u32 index, int isAif,
287+ int isFastResponse, struct hw_fib *aif_fib)
287288 {
288289 unsigned long mflags;
289290 dprintk((KERN_INFO "aac_intr_normal(%p,%x)\n", dev, index));
@@ -305,12 +306,14 @@ unsigned int aac_intr_normal(struct aac_dev *dev, u32 index, · 15 unmodified lines
305306 kfree (fib);
306307 return 1;
307308 }
308− if (aif_fib != NULL) {
309+ if (dev->sa_firmware) {
310+ fib->hbacmd_size = index; /* store event type */
311+ } else if (aif_fib != NULL) {
309312 memcpy(hw_fib, aif_fib, sizeof(struct hw_fib));
310313 } else {
311− memcpy(hw_fib,
312− (struct hw_fib *)(((uintptr_t)(dev->regs.sa)) +
313− index), sizeof(struct hw_fib));
314+ memcpy(hw_fib, (struct hw_fib *)
315+ (((uintptr_t)(dev->regs.sa)) + index),
316+ sizeof(struct hw_fib));
314317 }
315318 INIT_LIST_HEAD(&fib->fiblink);
316319 fib->type = FSAFS_NTC_FIB_CONTEXT;
@@ -344,7 +347,7 @@ unsigned int aac_intr_normal(struct aac_dev *dev, u32 index, · 27 unmodified lines
344347 (fib_callback)aac_aif_callback, fibctx);
345348 } else {
346349 struct fib *fib = &dev->fibs[index];
347− struct hw_fib * hwfib = fib->hw_fib_va;
350+ int start_callback = 0;
348351
349352 /*
350353 * Remove this fib from the Outstanding I/O queue.
@@ -362,60 +365,104 @@ unsigned int aac_intr_normal(struct aac_dev *dev, u32 index, · 11 unmodified lines
362365 return 0;
363366 }
364367
365− if (isFastResponse) {
366− /*
367− * Doctor the fib
368− */
369− *(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
370− hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
371− fib->flags |= FIB_CONTEXT_FLAG_FASTRESP;
372− }
373−
374368 FIB_COUNTER_INCREMENT(aac_config.FibRecved);
375369
376− if (hwfib->header.Command == cpu_to_le16(NuFileSystem))
377− {
378− __le32 *pstatus = (__le32 *)hwfib->data;
379− if (*pstatus & cpu_to_le32(0xffff0000))
380− *pstatus = cpu_to_le32(ST_OK);
381− }
382− if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected | Async))
383− {
384− if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected))
385− FIB_COUNTER_INCREMENT(aac_config.NoResponseRecved);
386− else
387− FIB_COUNTER_INCREMENT(aac_config.AsyncRecved);
388− /*
389− * NOTE: we cannot touch the fib after this
390− * call, because it may have been deallocated.
391− */
392− if (likely(fib->callback && fib->callback_data)) {
393− fib->flags &= FIB_CONTEXT_FLAG_FASTRESP;
394− fib->callback(fib->callback_data, fib);
395− } else
396− dev_info(&dev->pdev->dev,
397− "Invalid callback_fib[%d] (*%p)(%p)\n",
398− index, fib->callback, fib->callback_data);
370+ if (fib->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) {
371+
372+ if (isFastResponse)
373+ fib->flags |= FIB_CONTEXT_FLAG_FASTRESP;
374+
375+ if (fib->callback) {
376+ start_callback = 1;
377+ } else {
378+ unsigned long flagv;
379+ int complete = 0;
380+
381+ dprintk((KERN_INFO "event_wait up\n"));
382+ spin_lock_irqsave(&fib->event_lock, flagv);
383+ if (fib->done == 2) {
384+ fib->done = 1;
385+ complete = 1;
386+ } else {
387+ fib->done = 1;
388+ up(&fib->event_wait);
389+ }
390+ spin_unlock_irqrestore(&fib->event_lock, flagv);
391+
392+ spin_lock_irqsave(&dev->manage_lock, mflags);
393+ dev->management_fib_count--;
394+ spin_unlock_irqrestore(&dev->manage_lock,
395+ mflags);
396+
397+ FIB_COUNTER_INCREMENT(aac_config.NativeRecved);
398+ if (complete)
399+ aac_fib_complete(fib);
400+ }
399401 } else {
400− unsigned long flagv;
401− dprintk((KERN_INFO "event_wait up\n"));
402− spin_lock_irqsave(&fib->event_lock, flagv);
403− if (!fib->done) {
404− fib->done = 1;
405− up(&fib->event_wait);
402+ struct hw_fib *hwfib = fib->hw_fib_va;
403+
404+ if (isFastResponse) {
405+ /* Doctor the fib */
406+ *(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
407+ hwfib->header.XferState |=
408+ cpu_to_le32(AdapterProcessed);
409+ fib->flags |= FIB_CONTEXT_FLAG_FASTRESP;
406410 }
407− spin_unlock_irqrestore(&fib->event_lock, flagv);
408411
409− spin_lock_irqsave(&dev->manage_lock, mflags);
410− dev->management_fib_count--;
411− spin_unlock_irqrestore(&dev->manage_lock, mflags);
412+ if (hwfib->header.Command ==
413+ cpu_to_le16(NuFileSystem)) {
414+ __le32 *pstatus = (__le32 *)hwfib->data;
412415
413− FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
414− if (fib->done == 2) {
416+ if (*pstatus & cpu_to_le32(0xffff0000))
417+ *pstatus = cpu_to_le32(ST_OK);
418+ }
419+ if (hwfib->header.XferState &
420+ cpu_to_le32(NoResponseExpected | Async)) {
421+ if (hwfib->header.XferState & cpu_to_le32(
422+ NoResponseExpected))
423+ FIB_COUNTER_INCREMENT(
424+ aac_config.NoResponseRecved);
425+ else
426+ FIB_COUNTER_INCREMENT(
427+ aac_config.AsyncRecved);
428+ start_callback = 1;
429+ } else {
430+ unsigned long flagv;
431+ int complete = 0;
432+
433+ dprintk((KERN_INFO "event_wait up\n"));
415434 spin_lock_irqsave(&fib->event_lock, flagv);
416− fib->done = 0;
435+ if (fib->done == 2) {
436+ fib->done = 1;
437+ complete = 1;
438+ } else {
439+ fib->done = 1;
440+ up(&fib->event_wait);
441+ }
417442 spin_unlock_irqrestore(&fib->event_lock, flagv);
443+
444+ spin_lock_irqsave(&dev->manage_lock, mflags);
445+ dev->management_fib_count--;
446+ spin_unlock_irqrestore(&dev->manage_lock,
447+ mflags);
448+
449+ FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
450+ if (complete)
451+ aac_fib_complete(fib);
452+ }
453+ }
454+
455+
456+ if (start_callback) {
457+ /*
458+ * NOTE: we cannot touch the fib after this
459+ * call, because it may have been deallocated.
460+ */
461+ if (likely(fib->callback && fib->callback_data)) {
462+ fib->callback(fib->callback_data, fib);
463+ } else {
418464 aac_fib_complete(fib);
465+ aac_fib_free(fib);
419466 }
420467
421468 }
drivers/scsi/aacraid/linit.c+387−175
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -57,7 +58,7 @@ · 44 unmodified lines
5758
5859 #include "aacraid.h"
5960
60−#define AAC_DRIVER_VERSION "1.2-1"
61+#define AAC_DRIVER_VERSION "1.2.1"
6162 #ifndef AAC_DRIVER_BRANCH
6263 #define AAC_DRIVER_BRANCH ""
6364 #endif
@@ -401,61 +402,89 @@ static int aac_biosparm(struct scsi_device *sdev, struct block_device *bdev, · 337 unmodified lines
401402 static int aac_slave_configure(struct scsi_device *sdev)
402403 {
403404 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
405+ int chn, tid;
406+ unsigned int depth = 0;
407+ unsigned int set_timeout = 0;
408+
409+ chn = aac_logical_to_phys(sdev_channel(sdev));
410+ tid = sdev_id(sdev);
411+ if (chn < AAC_MAX_BUSES && tid < AAC_MAX_TARGETS &&
412+ aac->hba_map[chn][tid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
413+ depth = aac->hba_map[chn][tid].qd_limit;
414+ set_timeout = 1;
415+ goto common_config;
416+ }
417+
418+
404419 if (aac->jbod && (sdev->type == TYPE_DISK))
405420 sdev->removable = 1;
406− if ((sdev->type == TYPE_DISK) &&
407− (sdev_channel(sdev) != CONTAINER_CHANNEL) &&
408− (!aac->jbod || sdev->inq_periph_qual) &&
409− (!aac->raid_scsi_mode || (sdev_channel(sdev) != 2))) {
421+
422+ if (sdev->type == TYPE_DISK
423+ && sdev_channel(sdev) != CONTAINER_CHANNEL
424+ && (!aac->jbod || sdev->inq_periph_qual)
425+ && (!aac->raid_scsi_mode || (sdev_channel(sdev) != 2))) {
426+
410427 if (expose_physicals == 0)
411428 return -ENXIO;
429+
412430 if (expose_physicals < 0)
413431 sdev->no_uld_attach = 1;
414432 }
415− if (sdev->tagged_supported && (sdev->type == TYPE_DISK) &&
416− (!aac->raid_scsi_mode || (sdev_channel(sdev) != 2)) &&
417− !sdev->no_uld_attach) {
433+
434+ if (sdev->tagged_supported
435+ && sdev->type == TYPE_DISK
436+ && (!aac->raid_scsi_mode || (sdev_channel(sdev) != 2))
437+ && !sdev->no_uld_attach) {
438+
418439 struct scsi_device * dev;
419440 struct Scsi_Host *host = sdev->host;
420441 unsigned num_lsu = 0;
421442 unsigned num_one = 0;
422− unsigned depth;
423443 unsigned cid;
424444
425− /*
426− * Firmware has an individual device recovery time typically
427− * of 35 seconds, give us a margin.
428− */
429− if (sdev->request_queue->rq_timeout < (45 * HZ))
430− blk_queue_rq_timeout(sdev->request_queue, 45*HZ);
445+ set_timeout = 1;
446+
431447 for (cid = 0; cid < aac->maximum_num_containers; ++cid)
432448 if (aac->fsa_dev[cid].valid)
433449 ++num_lsu;
450+
434451 __shost_for_each_device(dev, host) {
435− if (dev->tagged_supported && (dev->type == TYPE_DISK) &&
436− (!aac->raid_scsi_mode ||
437− (sdev_channel(sdev) != 2)) &&
438− !dev->no_uld_attach) {
452+ if (dev->tagged_supported
453+ && dev->type == TYPE_DISK
454+ && (!aac->raid_scsi_mode || (sdev_channel(sdev) != 2))
455+ && !dev->no_uld_attach) {
439456 if ((sdev_channel(dev) != CONTAINER_CHANNEL)
440− || !aac->fsa_dev[sdev_id(dev)].valid)
457+ || !aac->fsa_dev[sdev_id(dev)].valid) {
441458 ++num_lsu;
442− } else
459+ }
460+ } else {
443461 ++num_one;
462+ }
444463 }
464+
445465 if (num_lsu == 0)
446466 ++num_lsu;
447− depth = (host->can_queue - num_one) / num_lsu;
448− if (depth > 256)
449− depth = 256;
450− else if (depth < 2)
451− depth = 2;
452− scsi_change_queue_depth(sdev, depth);
453− } else {
454− scsi_change_queue_depth(sdev, 1);
455467
456− sdev->tagged_supported = 1;
468+ depth = (host->can_queue - num_one) / num_lsu;
457469 }
458470
471+common_config:
472+ /*
473+ * Firmware has an individual device recovery time typically
474+ * of 35 seconds, give us a margin.
475+ */
476+ if (set_timeout && sdev->request_queue->rq_timeout < (45 * HZ))
477+ blk_queue_rq_timeout(sdev->request_queue, 45*HZ);
478+
479+ if (depth > 256)
480+ depth = 256;
481+ else if (depth < 1)
482+ depth = 1;
483+
484+ scsi_change_queue_depth(sdev, depth);
485+
486+ sdev->tagged_supported = 1;
487+
459488 return 0;
460489 }
461490
@@ -470,6 +499,15 @@ static int aac_slave_configure(struct scsi_device *sdev) · 8 unmodified lines
470499
471500 static int aac_change_queue_depth(struct scsi_device *sdev, int depth)
472501 {
502+ struct aac_dev *aac = (struct aac_dev *)(sdev->host->hostdata);
503+ int chn, tid, is_native_device = 0;
504+
505+ chn = aac_logical_to_phys(sdev_channel(sdev));
506+ tid = sdev_id(sdev);
507+ if (chn < AAC_MAX_BUSES && tid < AAC_MAX_TARGETS &&
508+ aac->hba_map[chn][tid].devtype == AAC_DEVTYPE_NATIVE_RAW)
509+ is_native_device = 1;
510+
473511 if (sdev->tagged_supported && (sdev->type == TYPE_DISK) &&
474512 (sdev_channel(sdev) == CONTAINER_CHANNEL)) {
475513 struct scsi_device * dev;
@@ -491,9 +529,12 @@ static int aac_change_queue_depth(struct scsi_device *sdev, int depth) · 15 unmodified lines
491529 else if (depth < 2)
492530 depth = 2;
493531 return scsi_change_queue_depth(sdev, depth);
532+ } else if (is_native_device) {
533+ scsi_change_queue_depth(sdev, aac->hba_map[chn][tid].qd_limit);
534+ } else {
535+ scsi_change_queue_depth(sdev, 1);
494536 }
495−
496− return scsi_change_queue_depth(sdev, 1);
537+ return sdev->queue_depth;
497538 }
498539
499540 static ssize_t aac_show_raid_level(struct device *dev, struct device_attribute *attr, char *buf)
@@ -516,8 +557,39 @@ static struct device_attribute aac_raid_level_attr = { · 16 unmodified lines
516557 .show = aac_show_raid_level
517558 };
518559
560+static ssize_t aac_show_unique_id(struct device *dev,
561+ struct device_attribute *attr, char *buf)
562+{
563+ struct scsi_device *sdev = to_scsi_device(dev);
564+ struct aac_dev *aac = (struct aac_dev *)(sdev->host->hostdata);
565+ unsigned char sn[16];
566+
567+ memset(sn, 0, sizeof(sn));
568+
569+ if (sdev_channel(sdev) == CONTAINER_CHANNEL)
570+ memcpy(sn, aac->fsa_dev[sdev_id(sdev)].identifier, sizeof(sn));
571+
572+ return snprintf(buf, 16 * 2 + 2,
573+ "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
574+ sn[0], sn[1], sn[2], sn[3],
575+ sn[4], sn[5], sn[6], sn[7],
576+ sn[8], sn[9], sn[10], sn[11],
577+ sn[12], sn[13], sn[14], sn[15]);
578+}
579+
580+static struct device_attribute aac_unique_id_attr = {
581+ .attr = {
582+ .name = "unique_id",
583+ .mode = 0444,
584+ },
585+ .show = aac_show_unique_id
586+};
587+
588+
589+
519590 static struct device_attribute *aac_dev_attrs[] = {
520591 &aac_raid_level_attr,
592+ &aac_unique_id_attr,
521593 NULL,
522594 };
523595
@@ -534,46 +606,136 @@ static int aac_eh_abort(struct scsi_cmnd* cmd) · 10 unmodified lines
534606 struct scsi_device * dev = cmd->device;
535607 struct Scsi_Host * host = dev->host;
536608 struct aac_dev * aac = (struct aac_dev *)host->hostdata;
537− int count;
609+ int count, found;
610+ u32 bus, cid;
538611 int ret = FAILED;
539612
540− printk(KERN_ERR "%s: Host adapter abort request (%d,%d,%d,%llu)\n",
541− AAC_DRIVERNAME,
542− host->host_no, sdev_channel(dev), sdev_id(dev), dev->lun);
543− switch (cmd->cmnd[0]) {
544− case SERVICE_ACTION_IN_16:
545− if (!(aac->raw_io_interface) ||
546− !(aac->raw_io_64) ||
547− ((cmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
548− break;
549− case INQUIRY:
550− case READ_CAPACITY:
551− /* Mark associated FIB to not complete, eh handler does this */
613+ bus = aac_logical_to_phys(scmd_channel(cmd));
614+ cid = scmd_id(cmd);
615+ if (aac->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
616+ struct fib *fib;
617+ struct aac_hba_tm_req *tmf;
618+ int status;
619+ u64 address;
620+ __le32 managed_request_id;
621+
622+ pr_err("%s: Host adapter abort request (%d,%d,%d,%d)\n",
623+ AAC_DRIVERNAME,
624+ host->host_no, sdev_channel(dev), sdev_id(dev), (int)dev->lun);
625+
626+ found = 0;
552627 for (count = 0; count < (host->can_queue + AAC_NUM_MGT_FIB); ++count) {
553− struct fib * fib = &aac->fibs[count];
554− if (fib->hw_fib_va->header.XferState &&
555− (fib->flags & FIB_CONTEXT_FLAG) &&
556− (fib->callback_data == cmd)) {
557− fib->flags |= FIB_CONTEXT_FLAG_TIMED_OUT;
558− cmd->SCp.phase = AAC_OWNER_ERROR_HANDLER;
628+ fib = &aac->fibs[count];
629+ if (*(u8 *)fib->hw_fib_va != 0 &&
630+ (fib->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) &&
631+ (fib->callback_data == cmd)) {
632+ found = 1;
633+ managed_request_id = ((struct aac_hba_cmd_req *)
634+ fib->hw_fib_va)->request_id;
635+ break;
636+ }
637+ }
638+ if (!found)
639+ return ret;
640+
641+ /* start a HBA_TMF_ABORT_TASK TMF request */
642+ fib = aac_fib_alloc(aac);
643+ if (!fib)
644+ return ret;
645+
646+ tmf = (struct aac_hba_tm_req *)fib->hw_fib_va;
647+ memset(tmf, 0, sizeof(*tmf));
648+ tmf->tmf = HBA_TMF_ABORT_TASK;
649+ tmf->it_nexus = aac->hba_map[bus][cid].rmw_nexus;
650+ tmf->lun[1] = cmd->device->lun;
651+
652+ address = (u64)fib->hw_error_pa;
653+ tmf->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
654+ tmf->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
655+ tmf->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
656+
657+ fib->hbacmd_size = sizeof(*tmf);
658+ cmd->SCp.sent_command = 0;
659+
660+ status = aac_hba_send(HBA_IU_TYPE_SCSI_TM_REQ, fib,
661+ (fib_callback) aac_hba_callback,
662+ (void *) cmd);
663+
664+ /* Wait up to 2 minutes for completion */
665+ for (count = 0; count < 120; ++count) {
666+ if (cmd->SCp.sent_command) {
559667 ret = SUCCESS;
668+ break;
560669 }
670+ msleep(1000);
561671 }
562− break;
563− case TEST_UNIT_READY:
564− /* Mark associated FIB to not complete, eh handler does this */
565− for (count = 0; count < (host->can_queue + AAC_NUM_MGT_FIB); ++count) {
566− struct scsi_cmnd * command;
567− struct fib * fib = &aac->fibs[count];
568− if ((fib->hw_fib_va->header.XferState & cpu_to_le32(Async | NoResponseExpected)) &&
569− (fib->flags & FIB_CONTEXT_FLAG) &&
570− ((command = fib->callback_data)) &&
571− (command->device == cmd->device)) {
572− fib->flags |= FIB_CONTEXT_FLAG_TIMED_OUT;
573− command->SCp.phase = AAC_OWNER_ERROR_HANDLER;
574− if (command == cmd)
672+
673+ if (ret != SUCCESS)
674+ pr_err("%s: Host adapter abort request timed out\n",
675+ AAC_DRIVERNAME);
676+ } else {
677+ pr_err(
678+ "%s: Host adapter abort request.\n"
679+ "%s: Outstanding commands on (%d,%d,%d,%d):\n",
680+ AAC_DRIVERNAME, AAC_DRIVERNAME,
681+ host->host_no, sdev_channel(dev), sdev_id(dev),
682+ (int)dev->lun);
683+ switch (cmd->cmnd[0]) {
684+ case SERVICE_ACTION_IN_16:
685+ if (!(aac->raw_io_interface) ||
686+ !(aac->raw_io_64) ||
687+ ((cmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
688+ break;
689+ case INQUIRY:
690+ case READ_CAPACITY:
691+ /*
692+ * Mark associated FIB to not complete,
693+ * eh handler does this
694+ */
695+ for (count = 0;
696+ count < (host->can_queue + AAC_NUM_MGT_FIB);
697+ ++count) {
698+ struct fib *fib = &aac->fibs[count];
699+
700+ if (fib->hw_fib_va->header.XferState &&
701+ (fib->flags & FIB_CONTEXT_FLAG) &&
702+ (fib->callback_data == cmd)) {
703+ fib->flags |=
704+ FIB_CONTEXT_FLAG_TIMED_OUT;
705+ cmd->SCp.phase =
706+ AAC_OWNER_ERROR_HANDLER;
575707 ret = SUCCESS;
708+ }
709+ }
710+ break;
711+ case TEST_UNIT_READY:
712+ /*
713+ * Mark associated FIB to not complete,
714+ * eh handler does this
715+ */
716+ for (count = 0;
717+ count < (host->can_queue + AAC_NUM_MGT_FIB);
718+ ++count) {
719+ struct scsi_cmnd *command;
720+ struct fib *fib = &aac->fibs[count];
721+
722+ command = fib->callback_data;
723+
724+ if ((fib->hw_fib_va->header.XferState &
725+ cpu_to_le32
726+ (Async | NoResponseExpected)) &&
727+ (fib->flags & FIB_CONTEXT_FLAG) &&
728+ ((command)) &&
729+ (command->device == cmd->device)) {
730+ fib->flags |=
731+ FIB_CONTEXT_FLAG_TIMED_OUT;
732+ command->SCp.phase =
733+ AAC_OWNER_ERROR_HANDLER;
734+ if (command == cmd)
735+ ret = SUCCESS;
736+ }
576737 }
738+ break;
577739 }
578740 }
579741 return ret;
@@ -588,70 +750,165 @@ static int aac_eh_reset(struct scsi_cmnd* cmd) · 8 unmodified lines
588750 {
589751 struct scsi_device * dev = cmd->device;
590752 struct Scsi_Host * host = dev->host;
591− struct scsi_cmnd * command;
592− int count;
593753 struct aac_dev * aac = (struct aac_dev *)host->hostdata;
594− unsigned long flags;
595−
596− /* Mark the associated FIB to not complete, eh handler does this */
597− for (count = 0; count < (host->can_queue + AAC_NUM_MGT_FIB); ++count) {
598− struct fib * fib = &aac->fibs[count];
599− if (fib->hw_fib_va->header.XferState &&
600− (fib->flags & FIB_CONTEXT_FLAG) &&
601− (fib->callback_data == cmd)) {
602− fib->flags |= FIB_CONTEXT_FLAG_TIMED_OUT;
603− cmd->SCp.phase = AAC_OWNER_ERROR_HANDLER;
754+ int count;
755+ u32 bus, cid;
756+ int ret = FAILED;
757+
758+ bus = aac_logical_to_phys(scmd_channel(cmd));
759+ cid = scmd_id(cmd);
760+ if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
761+ aac->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
762+ struct fib *fib;
763+ int status;
764+ u64 address;
765+ u8 command;
766+
767+ pr_err("%s: Host adapter reset request. SCSI hang ?\n",
768+ AAC_DRIVERNAME);
769+
770+ fib = aac_fib_alloc(aac);
771+ if (!fib)
772+ return ret;
773+
774+
775+ if (aac->hba_map[bus][cid].reset_state == 0) {
776+ struct aac_hba_tm_req *tmf;
777+
778+ /* start a HBA_TMF_LUN_RESET TMF request */
779+ tmf = (struct aac_hba_tm_req *)fib->hw_fib_va;
780+ memset(tmf, 0, sizeof(*tmf));
781+ tmf->tmf = HBA_TMF_LUN_RESET;
782+ tmf->it_nexus = aac->hba_map[bus][cid].rmw_nexus;
783+ tmf->lun[1] = cmd->device->lun;
784+
785+ address = (u64)fib->hw_error_pa;
786+ tmf->error_ptr_hi = cpu_to_le32
787+ ((u32)(address >> 32));
788+ tmf->error_ptr_lo = cpu_to_le32
789+ ((u32)(address & 0xffffffff));
790+ tmf->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
791+ fib->hbacmd_size = sizeof(*tmf);
792+
793+ command = HBA_IU_TYPE_SCSI_TM_REQ;
794+ aac->hba_map[bus][cid].reset_state++;
795+ } else if (aac->hba_map[bus][cid].reset_state >= 1) {
796+ struct aac_hba_reset_req *rst;
797+
798+ /* already tried, start a hard reset now */
799+ rst = (struct aac_hba_reset_req *)fib->hw_fib_va;
800+ memset(rst, 0, sizeof(*rst));
801+ /* reset_type is already zero... */
802+ rst->it_nexus = aac->hba_map[bus][cid].rmw_nexus;
803+
804+ address = (u64)fib->hw_error_pa;
805+ rst->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
806+ rst->error_ptr_lo = cpu_to_le32
807+ ((u32)(address & 0xffffffff));
808+ rst->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
809+ fib->hbacmd_size = sizeof(*rst);
810+
811+ command = HBA_IU_TYPE_SATA_REQ;
812+ aac->hba_map[bus][cid].reset_state = 0;
604813 }
605− }
606− printk(KERN_ERR "%s: Host adapter reset request. SCSI hang ?\n",
607− AAC_DRIVERNAME);
814+ cmd->SCp.sent_command = 0;
608815
609− if ((count = aac_check_health(aac)))
610− return count;
611− /*
612− * Wait for all commands to complete to this specific
613− * target (block maximum 60 seconds).
614− */
615− for (count = 60; count; --count) {
616− int active = aac->in_reset;
816+ status = aac_hba_send(command, fib,
817+ (fib_callback) aac_hba_callback,
818+ (void *) cmd);
617819
618− if (active == 0)
619− __shost_for_each_device(dev, host) {
620− spin_lock_irqsave(&dev->list_lock, flags);
621− list_for_each_entry(command, &dev->cmd_list, list) {
622− if ((command != cmd) &&
623− (command->SCp.phase == AAC_OWNER_FIRMWARE)) {
624− active++;
625− break;
626− }
627− }
628− spin_unlock_irqrestore(&dev->list_lock, flags);
629− if (active)
820+ /* Wait up to 2 minutes for completion */
821+ for (count = 0; count < 120; ++count) {
822+ if (cmd->SCp.sent_command) {
823+ ret = SUCCESS;
630824 break;
825+ }
826+ msleep(1000);
827+ }
631828
829+ if (ret != SUCCESS)
830+ pr_err("%s: Host adapter reset request timed out\n",
831+ AAC_DRIVERNAME);
832+ } else {
833+ struct scsi_cmnd *command;
834+ unsigned long flags;
835+
836+ /* Mark the assoc. FIB to not complete, eh handler does this */
837+ for (count = 0;
838+ count < (host->can_queue + AAC_NUM_MGT_FIB);
839+ ++count) {
840+ struct fib *fib = &aac->fibs[count];
841+
842+ if (fib->hw_fib_va->header.XferState &&
843+ (fib->flags & FIB_CONTEXT_FLAG) &&
844+ (fib->callback_data == cmd)) {
845+ fib->flags |= FIB_CONTEXT_FLAG_TIMED_OUT;
846+ cmd->SCp.phase = AAC_OWNER_ERROR_HANDLER;
847+ }
632848 }
849+
850+ pr_err("%s: Host adapter reset request. SCSI hang ?\n",
851+ AAC_DRIVERNAME);
852+
853+ count = aac_check_health(aac);
854+ if (count)
855+ return count;
633856 /*
634− * We can exit If all the commands are complete
857+ * Wait for all commands to complete to this specific
858+ * target (block maximum 60 seconds).
635859 */
636− if (active == 0)
637− return SUCCESS;
638− ssleep(1);
860+ for (count = 60; count; --count) {
861+ int active = aac->in_reset;
862+
863+ if (active == 0)
864+ __shost_for_each_device(dev, host) {
865+ spin_lock_irqsave(&dev->list_lock, flags);
866+ list_for_each_entry(command, &dev->cmd_list,
867+ list) {
868+ if ((command != cmd) &&
869+ (command->SCp.phase ==
870+ AAC_OWNER_FIRMWARE)) {
871+ active++;
872+ break;
873+ }
874+ }
875+ spin_unlock_irqrestore(&dev->list_lock, flags);
876+ if (active)
877+ break;
878+
879+ }
880+ /*
881+ * We can exit If all the commands are complete
882+ */
883+ if (active == 0)
884+ return SUCCESS;
885+ ssleep(1);
886+ }
887+ pr_err("%s: SCSI bus appears hung\n", AAC_DRIVERNAME);
888+
889+ /*
890+ * This adapter needs a blind reset, only do so for
891+ * Adapters that support a register, instead of a commanded,
892+ * reset.
893+ */
894+ if (((aac->supplement_adapter_info.SupportedOptions2 &
895+ AAC_OPTION_MU_RESET) ||
896+ (aac->supplement_adapter_info.SupportedOptions2 &
897+ AAC_OPTION_DOORBELL_RESET)) &&
898+ aac_check_reset &&
899+ ((aac_check_reset != 1) ||
900+ !(aac->supplement_adapter_info.SupportedOptions2 &
901+ AAC_OPTION_IGNORE_RESET))) {
902+ /* Bypass wait for command quiesce */
903+ aac_reset_adapter(aac, 2, IOP_HWSOFT_RESET);
904+ }
905+ ret = SUCCESS;
639906 }
640− printk(KERN_ERR "%s: SCSI bus appears hung\n", AAC_DRIVERNAME);
641907 /*
642− * This adapter needs a blind reset, only do so for Adapters that
643− * support a register, instead of a commanded, reset.
908+ * Cause an immediate retry of the command with a ten second delay
909+ * after successful tur
644910 */
645− if (((aac->supplement_adapter_info.SupportedOptions2 &
646− AAC_OPTION_MU_RESET) ||
647− (aac->supplement_adapter_info.SupportedOptions2 &
648− AAC_OPTION_DOORBELL_RESET)) &&
649− aac_check_reset &&
650− ((aac_check_reset != 1) ||
651− !(aac->supplement_adapter_info.SupportedOptions2 &
652− AAC_OPTION_IGNORE_RESET)))
653− aac_reset_adapter(aac, 2); /* Bypass wait for command quiesce */
654− return SUCCESS; /* Cause an immediate retry of the command with a ten second delay after successful tur */
911+ return ret;
655912 }
656913
657914 /**
@@ -911,10 +1168,16 @@ static ssize_t aac_store_reset_adapter(struct device *device, · 253 unmodified lines
9111168 const char *buf, size_t count)
9121169 {
9131170 int retval = -EACCES;
1171+ int bled = 0;
1172+ struct aac_dev *aac;
1173+
9141174
9151175 if (!capable(CAP_SYS_ADMIN))
9161176 return retval;
917− retval = aac_reset_adapter((struct aac_dev*)class_to_shost(device)->hostdata, buf[0] == '!');
1177+
1178+ aac = (struct aac_dev *)class_to_shost(device)->hostdata;
1179+ bled = buf[0] == '!' ? 1:0;
1180+ retval = aac_reset_adapter(aac, bled, IOP_HWSOFT_RESET);
9181181 if (retval >= 0)
9191182 retval = count;
9201183 return retval;
@@ -1070,6 +1333,7 @@ static void __aac_shutdown(struct aac_dev * aac) · 149 unmodified lines
10701333 {
10711334 int i;
10721335
1336+ aac->adapter_shutdown = 1;
10731337 aac_send_shutdown(aac);
10741338
10751339 if (aac->aif_thread) {
@@ -1285,7 +1549,7 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 209 unmodified lines
12851549 else
12861550 shost->this_id = shost->max_id;
12871551
1288− if (aac_drivers[index].quirks & AAC_QUIRK_SRC)
1552+ if (!aac->sa_firmware && aac_drivers[index].quirks & AAC_QUIRK_SRC)
12891553 aac_intr_normal(aac, 0, 2, 0, NULL);
12901554
12911555 /*
@@ -1327,35 +1591,12 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) · 35 unmodified lines
13271591
13281592 static void aac_release_resources(struct aac_dev *aac)
13291593 {
1330− int i;
1331−
13321594 aac_adapter_disable_int(aac);
1333− if (aac->pdev->device == PMC_DEVICE_S6 ||
1334− aac->pdev->device == PMC_DEVICE_S7 ||
1335− aac->pdev->device == PMC_DEVICE_S8 ||
1336− aac->pdev->device == PMC_DEVICE_S9) {
1337− if (aac->max_msix > 1) {
1338− for (i = 0; i < aac->max_msix; i++)
1339− free_irq(pci_irq_vector(aac->pdev, i),
1340− &(aac->aac_msix[i]));
1341− } else {
1342− free_irq(aac->pdev->irq, &(aac->aac_msix[0]));
1343− }
1344− } else {
1345− free_irq(aac->pdev->irq, aac);
1346− }
1347− if (aac->msi)
1348− pci_disable_msi(aac->pdev);
1349− else if (aac->max_msix > 1)
1350− pci_disable_msix(aac->pdev);
1351−
1595+ aac_free_irq(aac);
13521596 }
13531597
13541598 static int aac_acquire_resources(struct aac_dev *dev)
13551599 {
1356− int i, j;
1357− int instance = dev->id;
1358− const char *name = dev->name;
13591600 unsigned long status;
13601601 /*
13611602 * First clear out all interrupts. Then enable the one's that we
@@ -1377,37 +1618,8 @@ static int aac_acquire_resources(struct aac_dev *dev) · 15 unmodified lines
13771618 if (dev->msi_enabled)
13781619 aac_src_access_devreg(dev, AAC_ENABLE_MSIX);
13791620
1380− if (!dev->sync_mode && dev->msi_enabled && dev->max_msix > 1) {
1381− for (i = 0; i < dev->max_msix; i++) {
1382− dev->aac_msix[i].vector_no = i;
1383− dev->aac_msix[i].dev = dev;
1384−
1385− if (request_irq(pci_irq_vector(dev->pdev, i),
1386− dev->a_ops.adapter_intr,
1387− 0, "aacraid", &(dev->aac_msix[i]))) {
1388− printk(KERN_ERR "%s%d: Failed to register IRQ for vector %d.\n",
1389− name, instance, i);
1390− for (j = 0 ; j < i ; j++)
1391− free_irq(pci_irq_vector(dev->pdev, j),
1392− &(dev->aac_msix[j]));
1393− pci_disable_msix(dev->pdev);
1394− goto error_iounmap;
1395− }
1396− }
1397− } else {
1398− dev->aac_msix[0].vector_no = 0;
1399− dev->aac_msix[0].dev = dev;
1400−
1401− if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
1402− IRQF_SHARED, "aacraid",
1403− &(dev->aac_msix[0])) < 0) {
1404− if (dev->msi)
1405− pci_disable_msi(dev->pdev);
1406− printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
1407− name, instance);
1408− goto error_iounmap;
1409− }
1410− }
1621+ if (aac_acquire_irq(dev))
1622+ goto error_iounmap;
14111623
14121624 aac_adapter_enable_int(dev);
14131625
@@ -1420,7 +1632,7 @@ static int aac_acquire_resources(struct aac_dev *dev) · 6 unmodified lines
14201632 /* After EEH recovery or suspend resume, max_msix count
14211633 * may change, therfore updating in init as well.
14221634 */
1423− dev->init->Sa_MSIXVectors = cpu_to_le32(dev->max_msix);
1635+ dev->init->r7.no_of_msix_vectors = cpu_to_le32(dev->max_msix);
14241636 aac_adapter_start(dev);
14251637 }
14261638 return 0;
drivers/scsi/aacraid/nark.c+2−1
@@ -5,7 +5,8 @@ · 4 unmodified lines
55 * Adaptec aacraid device driver for Linux.
66 *
77 * Copyright (c) 2000-2010 Adaptec, Inc.
8− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
8+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
910 *
1011 * This program is free software; you can redistribute it and/or modify
1112 * it under the terms of the GNU General Public License as published by
drivers/scsi/aacraid/rkt.c+3−2
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -60,7 +61,7 @@ static int aac_rkt_select_comm(struct aac_dev *dev, int comm) · 47 unmodified lines
6061 * case warrants this half baked, but convenient, check here.
6162 */
6263 if (dev->scsi_host_ptr->can_queue > AAC_NUM_IO_FIB_RKT) {
63− dev->init->MaxIoCommands =
64+ dev->init->r7.max_io_commands =
6465 cpu_to_le32(AAC_NUM_IO_FIB_RKT + AAC_NUM_MGT_FIB);
6566 dev->scsi_host_ptr->can_queue = AAC_NUM_IO_FIB_RKT;
6667 }
drivers/scsi/aacraid/rx.c+10−7
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -315,10 +316,10 @@ static void aac_rx_notify_adapter(struct aac_dev *dev, u32 event) · 302 unmodified lines
315316
316317 static void aac_rx_start_adapter(struct aac_dev *dev)
317318 {
318− struct aac_init *init;
319+ union aac_init *init;
319320
320321 init = dev->init;
321− init->HostElapsedSeconds = cpu_to_le32(get_seconds());
322+ init->r7.host_elapsed_seconds = cpu_to_le32(get_seconds());
322323 // We can only use a 32 bit address here
323324 rx_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
324325 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
@@ -470,7 +471,7 @@ static int aac_rx_ioremap(struct aac_dev * dev, u32 size) · 145 unmodified lines
470471 return 0;
471472 }
472473
473−static int aac_rx_restart_adapter(struct aac_dev *dev, int bled)
474+static int aac_rx_restart_adapter(struct aac_dev *dev, int bled, u8 reset_type)
474475 {
475476 u32 var = 0;
476477
@@ -559,7 +560,7 @@ int _aac_rx_init(struct aac_dev *dev) · 82 unmodified lines
559560 dev->a_ops.adapter_enable_int = aac_rx_disable_interrupt;
560561 dev->OIMR = status = rx_readb (dev, MUnit.OIMR);
561562 if ((((status & 0x0c) != 0x0c) || aac_reset_devices || reset_devices) &&
562− !aac_rx_restart_adapter(dev, 0))
563+ !aac_rx_restart_adapter(dev, 0, IOP_HWSOFT_RESET))
563564 /* Make sure the Hardware FIFO is empty */
564565 while ((++restart < 512) &&
565566 (rx_readl(dev, MUnit.OutboundQueue) != 0xFFFFFFFFL));
@@ -568,7 +569,8 @@ int _aac_rx_init(struct aac_dev *dev) · 2 unmodified lines
568569 */
569570 status = rx_readl(dev, MUnit.OMRx[0]);
570571 if (status & KERNEL_PANIC) {
571− if (aac_rx_restart_adapter(dev, aac_rx_check_health(dev)))
572+ if (aac_rx_restart_adapter(dev,
573+ aac_rx_check_health(dev), IOP_HWSOFT_RESET))
572574 goto error_iounmap;
573575 ++restart;
574576 }
@@ -606,7 +608,8 @@ int _aac_rx_init(struct aac_dev *dev) · 31 unmodified lines
606608 ((startup_timeout > 60)
607609 ? (startup_timeout - 60)
608610 : (startup_timeout / 2))))) {
609− if (likely(!aac_rx_restart_adapter(dev, aac_rx_check_health(dev))))
611+ if (likely(!aac_rx_restart_adapter(dev,
612+ aac_rx_check_health(dev), IOP_HWSOFT_RESET)))
610613 start = jiffies;
611614 ++restart;
612615 }
drivers/scsi/aacraid/sa.c+5−4
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -245,19 +246,19 @@ static void aac_sa_interrupt_adapter (struct aac_dev *dev) · 232 unmodified lines
245246
246247 static void aac_sa_start_adapter(struct aac_dev *dev)
247248 {
248− struct aac_init *init;
249+ union aac_init *init;
249250 /*
250251 * Fill in the remaining pieces of the init.
251252 */
252253 init = dev->init;
253− init->HostElapsedSeconds = cpu_to_le32(get_seconds());
254+ init->r7.host_elapsed_seconds = cpu_to_le32(get_seconds());
254255 /* We can only use a 32 bit address here */
255256 sa_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS,
256257 (u32)(ulong)dev->init_pa, 0, 0, 0, 0, 0,
257258 NULL, NULL, NULL, NULL, NULL);
258259 }
259260
260−static int aac_sa_restart_adapter(struct aac_dev *dev, int bled)
261+static int aac_sa_restart_adapter(struct aac_dev *dev, int bled, u8 reset_type)
261262 {
262263 return -EINVAL;
263264 }
drivers/scsi/aacraid/src.c+246−90
@@ -6,7 +6,8 @@ · 5 unmodified lines
66 * Adaptec aacraid device driver for Linux.
77 *
88 * Copyright (c) 2000-2010 Adaptec, Inc.
9− * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
9+ * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10+ * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1011 *
1112 * This program is free software; you can redistribute it and/or modify
1213 * it under the terms of the GNU General Public License as published by
@@ -135,8 +136,16 @@ static irqreturn_t aac_src_intr_message(int irq, void *dev_id) · 122 unmodified lines
135136
136137 if (mode & AAC_INT_MODE_AIF) {
137138 /* handle AIF */
138− if (dev->aif_thread && dev->fsa_dev)
139− aac_intr_normal(dev, 0, 2, 0, NULL);
139+ if (dev->sa_firmware) {
140+ u32 events = src_readl(dev, MUnit.SCR0);
141+
142+ aac_intr_normal(dev, events, 1, 0, NULL);
143+ writel(events, &dev->IndexRegs->Mailbox[0]);
144+ src_writel(dev, MUnit.IDR, 1 << 23);
145+ } else {
146+ if (dev->aif_thread && dev->fsa_dev)
147+ aac_intr_normal(dev, 0, 2, 0, NULL);
148+ }
140149 if (dev->msi_enabled)
141150 aac_src_access_devreg(dev, AAC_CLEAR_AIF_BIT);
142151 mode = 0;
@@ -148,17 +157,19 @@ static irqreturn_t aac_src_intr_message(int irq, void *dev_id) · 5 unmodified lines
148157 for (;;) {
149158 isFastResponse = 0;
150159 /* remove toggle bit (31) */
151− handle = (dev->host_rrq[index] & 0x7fffffff);
152− /* check fast response bit (30) */
160+ handle = le32_to_cpu((dev->host_rrq[index])
161+ & 0x7fffffff);
162+ /* check fast response bits (30, 1) */
153163 if (handle & 0x40000000)
154164 isFastResponse = 1;
155165 handle &= 0x0000ffff;
156166 if (handle == 0)
157167 break;
168+ handle >>= 2;
158169 if (dev->msi_enabled && dev->max_msix > 1)
159170 atomic_dec(&dev->rrq_outstanding[vector_no]);
171+ aac_intr_normal(dev, handle, 0, isFastResponse, NULL);
160172 dev->host_rrq[index++] = 0;
161− aac_intr_normal(dev, handle-1, 0, isFastResponse, NULL);
162173 if (index == (vector_no + 1) * dev->vector_cap)
163174 index = vector_no * dev->vector_cap;
164175 dev->host_rrq_idx[vector_no] = index;
@@ -384,7 +395,7 @@ static void aac_src_notify_adapter(struct aac_dev *dev, u32 event) · 219 unmodified lines
384395
385396 static void aac_src_start_adapter(struct aac_dev *dev)
386397 {
387− struct aac_init *init;
398+ union aac_init *init;
388399 int i;
389400
390401 /* reset host_rrq_idx first */
@@ -392,14 +403,26 @@ static void aac_src_start_adapter(struct aac_dev *dev) · 1 unmodified line
392403 dev->host_rrq_idx[i] = i * dev->vector_cap;
393404 atomic_set(&dev->rrq_outstanding[i], 0);
394405 }
406+ atomic_set(&dev->msix_counter, 0);
395407 dev->fibs_pushed_no = 0;
396408
397409 init = dev->init;
398− init->HostElapsedSeconds = cpu_to_le32(get_seconds());
410+ if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) {
411+ init->r8.host_elapsed_seconds = cpu_to_le32(get_seconds());
412+ src_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS,
413+ lower_32_bits(dev->init_pa),
414+ upper_32_bits(dev->init_pa),
415+ sizeof(struct _r8) +
416+ (AAC_MAX_HRRQ - 1) * sizeof(struct _rrq),
417+ 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
418+ } else {
419+ init->r7.host_elapsed_seconds = cpu_to_le32(get_seconds());
420+ // We can only use a 32 bit address here
421+ src_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS,
422+ (u32)(ulong)dev->init_pa, 0, 0, 0, 0, 0,
423+ NULL, NULL, NULL, NULL, NULL);
424+ }
399425
400− /* We can only use a 32 bit address here */
401− src_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
402− 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
403426 }
404427
405428 /**
@@ -435,6 +458,11 @@ static int aac_src_check_health(struct aac_dev *dev) · 29 unmodified lines
435458 return 0;
436459 }
437460
461+static inline u32 aac_get_vector(struct aac_dev *dev)
462+{
463+ return atomic_inc_return(&dev->msix_counter)%dev->max_msix;
464+}
465+
438466 /**
439467 * aac_src_deliver_message
440468 * @fib: fib to issue
@@ -448,66 +476,125 @@ static int aac_src_deliver_message(struct fib *fib) · 7 unmodified lines
448476 u32 fibsize;
449477 dma_addr_t address;
450478 struct aac_fib_xporthdr *pFibX;
479+ int native_hba;
451480 #if !defined(writeq)
452481 unsigned long flags;
453482 #endif
454483
455− u16 hdr_size = le16_to_cpu(fib->hw_fib_va->header.Size);
456484 u16 vector_no;
457485
458486 atomic_inc(&q->numpending);
459487
460− if (dev->msi_enabled && fib->hw_fib_va->header.Command != AifRequest &&
461− dev->max_msix > 1) {
462− vector_no = fib->vector_no;
463− fib->hw_fib_va->header.Handle += (vector_no << 16);
488+ native_hba = (fib->flags & FIB_CONTEXT_FLAG_NATIVE_HBA) ? 1 : 0;
489+
490+
491+ if (dev->msi_enabled && dev->max_msix > 1 &&
492+ (native_hba || fib->hw_fib_va->header.Command != AifRequest)) {
493+
494+ if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE3)
495+ && dev->sa_firmware)
496+ vector_no = aac_get_vector(dev);
497+ else
498+ vector_no = fib->vector_no;
499+
500+ if (native_hba) {
501+ if (fib->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF) {
502+ struct aac_hba_tm_req *tm_req;
503+
504+ tm_req = (struct aac_hba_tm_req *)
505+ fib->hw_fib_va;
506+ if (tm_req->iu_type ==
507+ HBA_IU_TYPE_SCSI_TM_REQ) {
508+ ((struct aac_hba_tm_req *)
509+ fib->hw_fib_va)->reply_qid
510+ = vector_no;
511+ ((struct aac_hba_tm_req *)
512+ fib->hw_fib_va)->request_id
513+ += (vector_no << 16);
514+ } else {
515+ ((struct aac_hba_reset_req *)
516+ fib->hw_fib_va)->reply_qid
517+ = vector_no;
518+ ((struct aac_hba_reset_req *)
519+ fib->hw_fib_va)->request_id
520+ += (vector_no << 16);
521+ }
522+ } else {
523+ ((struct aac_hba_cmd_req *)
524+ fib->hw_fib_va)->reply_qid
525+ = vector_no;
526+ ((struct aac_hba_cmd_req *)
527+ fib->hw_fib_va)->request_id
528+ += (vector_no << 16);
529+ }
530+ } else {
531+ fib->hw_fib_va->header.Handle += (vector_no << 16);
532+ }
464533 } else {
465534 vector_no = 0;
466535 }
467536
468537 atomic_inc(&dev->rrq_outstanding[vector_no]);
469538
470− if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
471− /* Calculate the amount to the fibsize bits */
472− fibsize = (hdr_size + 127) / 128 - 1;
473− if (fibsize > (ALIGN32 - 1))
474− return -EMSGSIZE;
475− /* New FIB header, 32-bit */
539+ if (native_hba) {
476540 address = fib->hw_fib_pa;
477− fib->hw_fib_va->header.StructType = FIB_MAGIC2;
478− fib->hw_fib_va->header.SenderFibAddress = (u32)address;
479− fib->hw_fib_va->header.u.TimeStamp = 0;
480− BUG_ON(upper_32_bits(address) != 0L);
541+ fibsize = (fib->hbacmd_size + 127) / 128 - 1;
542+ if (fibsize > 31)
543+ fibsize = 31;
481544 address |= fibsize;
545+#if defined(writeq)
546+ src_writeq(dev, MUnit.IQN_L, (u64)address);
547+#else
548+ spin_lock_irqsave(&fib->dev->iq_lock, flags);
549+ src_writel(dev, MUnit.IQN_H,
550+ upper_32_bits(address) & 0xffffffff);
551+ src_writel(dev, MUnit.IQN_L, address & 0xffffffff);
552+ spin_unlock_irqrestore(&fib->dev->iq_lock, flags);
553+#endif
482554 } else {
483− /* Calculate the amount to the fibsize bits */
484− fibsize = (sizeof(struct aac_fib_xporthdr) + hdr_size + 127) / 128 - 1;
485− if (fibsize > (ALIGN32 - 1))
486− return -EMSGSIZE;
487−
488− /* Fill XPORT header */
489− pFibX = (void *)fib->hw_fib_va - sizeof(struct aac_fib_xporthdr);
490− pFibX->Handle = cpu_to_le32(fib->hw_fib_va->header.Handle);
491− pFibX->HostAddress = cpu_to_le64(fib->hw_fib_pa);
492− pFibX->Size = cpu_to_le32(hdr_size);
493−
494− /*
495− * The xport header has been 32-byte aligned for us so that fibsize
496− * can be masked out of this address by hardware. -- BenC
497− */
498− address = fib->hw_fib_pa - sizeof(struct aac_fib_xporthdr);
499− if (address & (ALIGN32 - 1))
500− return -EINVAL;
555+ if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
556+ dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) {
557+ /* Calculate the amount to the fibsize bits */
558+ fibsize = (le16_to_cpu(fib->hw_fib_va->header.Size)
559+ + 127) / 128 - 1;
560+ /* New FIB header, 32-bit */
561+ address = fib->hw_fib_pa;
562+ fib->hw_fib_va->header.StructType = FIB_MAGIC2;
563+ fib->hw_fib_va->header.SenderFibAddress =
564+ cpu_to_le32((u32)address);
565+ fib->hw_fib_va->header.u.TimeStamp = 0;
566+ WARN_ON(upper_32_bits(address) != 0L);
567+ } else {
568+ /* Calculate the amount to the fibsize bits */
569+ fibsize = (sizeof(struct aac_fib_xporthdr) +
570+ le16_to_cpu(fib->hw_fib_va->header.Size)
571+ + 127) / 128 - 1;
572+ /* Fill XPORT header */
573+ pFibX = (struct aac_fib_xporthdr *)
574+ ((unsigned char *)fib->hw_fib_va -
575+ sizeof(struct aac_fib_xporthdr));
576+ pFibX->Handle = fib->hw_fib_va->header.Handle;
577+ pFibX->HostAddress =
578+ cpu_to_le64((u64)fib->hw_fib_pa);
579+ pFibX->Size = cpu_to_le32(
580+ le16_to_cpu(fib->hw_fib_va->header.Size));
581+ address = fib->hw_fib_pa -
582+ (u64)sizeof(struct aac_fib_xporthdr);
583+ }
584+ if (fibsize > 31)
585+ fibsize = 31;
501586 address |= fibsize;
502− }
587+
503588 #if defined(writeq)
504− src_writeq(dev, MUnit.IQ_L, (u64)address);
589+ src_writeq(dev, MUnit.IQ_L, (u64)address);
505590 #else
506− spin_lock_irqsave(&fib->dev->iq_lock, flags);
507− src_writel(dev, MUnit.IQ_H, upper_32_bits(address) & 0xffffffff);
508− src_writel(dev, MUnit.IQ_L, address & 0xffffffff);
509− spin_unlock_irqrestore(&fib->dev->iq_lock, flags);
591+ spin_lock_irqsave(&fib->dev->iq_lock, flags);
592+ src_writel(dev, MUnit.IQ_H,
593+ upper_32_bits(address) & 0xffffffff);
594+ src_writel(dev, MUnit.IQ_L, address & 0xffffffff);
595+ spin_unlock_irqrestore(&fib->dev->iq_lock, flags);
510596 #endif
597+ }
511598 return 0;
512599 }
513600
@@ -553,52 +640,117 @@ static int aac_srcv_ioremap(struct aac_dev *dev, u32 size) · 39 unmodified lines
553640 dev->base = dev->regs.src.bar0 = NULL;
554641 return 0;
555642 }
643+
644+ dev->regs.src.bar1 =
645+ ioremap(pci_resource_start(dev->pdev, 2), AAC_MIN_SRCV_BAR1_SIZE);
646+ dev->base = NULL;
647+ if (dev->regs.src.bar1 == NULL)
648+ return -1;
556649 dev->base = dev->regs.src.bar0 = ioremap(dev->base_start, size);
557− if (dev->base == NULL)
650+ if (dev->base == NULL) {
651+ iounmap(dev->regs.src.bar1);
652+ dev->regs.src.bar1 = NULL;
558653 return -1;
654+ }
559655 dev->IndexRegs = &((struct src_registers __iomem *)
560656 dev->base)->u.denali.IndexRegs;
561657 return 0;
562658 }
563659
564−static int aac_src_restart_adapter(struct aac_dev *dev, int bled)
660+static void aac_set_intx_mode(struct aac_dev *dev)
661+{
662+ if (dev->msi_enabled) {
663+ aac_src_access_devreg(dev, AAC_ENABLE_INTX);
664+ dev->msi_enabled = 0;
665+ msleep(5000); /* Delay 5 seconds */
666+ }
667+}
668+
669+static void aac_send_iop_reset(struct aac_dev *dev, int bled)
565670 {
566671 u32 var, reset_mask;
567672
568− if (bled >= 0) {
569− if (bled)
570− printk(KERN_ERR "%s%d: adapter kernel panic'd %x.\n",
673+ bled = aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS,
674+ 0, 0, 0, 0, 0, 0, &var,
675+ &reset_mask, NULL, NULL, NULL);
676+
677+ if ((bled || var != 0x00000001) && !dev->doorbell_mask)
678+ bled = -EINVAL;
679+ else if (dev->doorbell_mask) {
680+ reset_mask = dev->doorbell_mask;
681+ bled = 0;
682+ var = 0x00000001;
683+ }
684+
685+ aac_set_intx_mode(dev);
686+
687+ if (!bled && (dev->supplement_adapter_info.SupportedOptions2 &
688+ AAC_OPTION_DOORBELL_RESET)) {
689+ src_writel(dev, MUnit.IDR, reset_mask);
690+ } else {
691+ src_writel(dev, MUnit.IDR, 0x100);
692+ }
693+ msleep(30000);
694+}
695+
696+static void aac_send_hardware_soft_reset(struct aac_dev *dev)
697+{
698+ u_int32_t val;
699+
700+ val = readl(((char *)(dev->base) + IBW_SWR_OFFSET));
701+ val |= 0x01;
702+ writel(val, ((char *)(dev->base) + IBW_SWR_OFFSET));
703+ msleep_interruptible(20000);
704+}
705+
706+static int aac_src_restart_adapter(struct aac_dev *dev, int bled, u8 reset_type)
707+{
708+ unsigned long status, start;
709+
710+ if (bled < 0)
711+ goto invalid_out;
712+
713+ if (bled)
714+ pr_err("%s%d: adapter kernel panic'd %x.\n",
571715 dev->name, dev->id, bled);
572− dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
573− bled = aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS,
574− 0, 0, 0, 0, 0, 0, &var, &reset_mask, NULL, NULL, NULL);
575− if ((bled || (var != 0x00000001)) &&
576− !dev->doorbell_mask)
577− return -EINVAL;
578− else if (dev->doorbell_mask) {
579− reset_mask = dev->doorbell_mask;
580− bled = 0;
581− var = 0x00000001;
582− }
583716
584− if ((dev->pdev->device == PMC_DEVICE_S7 ||
585− dev->pdev->device == PMC_DEVICE_S8 ||
586− dev->pdev->device == PMC_DEVICE_S9) && dev->msi_enabled) {
587− aac_src_access_devreg(dev, AAC_ENABLE_INTX);
588− dev->msi_enabled = 0;
589− msleep(5000); /* Delay 5 seconds */
590− }
717+ dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
591718
592− if (!bled && (dev->supplement_adapter_info.SupportedOptions2 &
593− AAC_OPTION_DOORBELL_RESET)) {
594− src_writel(dev, MUnit.IDR, reset_mask);
595− ssleep(45);
596− } else {
597− src_writel(dev, MUnit.IDR, 0x100);
598− ssleep(45);
719+ switch (reset_type) {
720+ case IOP_HWSOFT_RESET:
721+ aac_send_iop_reset(dev, bled);
722+ /*
723+ * Check to see if KERNEL_UP_AND_RUNNING
724+ * Wait for the adapter to be up and running.
725+ * If !KERNEL_UP_AND_RUNNING issue HW Soft Reset
726+ */
727+ status = src_readl(dev, MUnit.OMR);
728+ if (dev->sa_firmware
729+ && !(status & KERNEL_UP_AND_RUNNING)) {
730+ start = jiffies;
731+ do {
732+ status = src_readl(dev, MUnit.OMR);
733+ if (time_after(jiffies,
734+ start+HZ*SOFT_RESET_TIME)) {
735+ aac_send_hardware_soft_reset(dev);
736+ start = jiffies;
737+ }
738+ } while (!(status & KERNEL_UP_AND_RUNNING));
599739 }
740+ break;
741+ case HW_SOFT_RESET:
742+ if (dev->sa_firmware) {
743+ aac_send_hardware_soft_reset(dev);
744+ aac_set_intx_mode(dev);
745+ }
746+ break;
747+ default:
748+ aac_send_iop_reset(dev, bled);
749+ break;
600750 }
601751
752+invalid_out:
753+
602754 if (src_readl(dev, MUnit.OMR) & KERNEL_PANIC)
603755 return -ENODEV;
604756
@@ -653,14 +805,15 @@ int aac_src_init(struct aac_dev *dev) · 48 unmodified lines
653805 dev->a_ops.adapter_sync_cmd = src_sync_cmd;
654806 dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
655807 if ((aac_reset_devices || reset_devices) &&
656− !aac_src_restart_adapter(dev, 0))
808+ !aac_src_restart_adapter(dev, 0, IOP_HWSOFT_RESET))
657809 ++restart;
658810 /*
659811 * Check to see if the board panic'd while booting.
660812 */
661813 status = src_readl(dev, MUnit.OMR);
662814 if (status & KERNEL_PANIC) {
663− if (aac_src_restart_adapter(dev, aac_src_check_health(dev)))
815+ if (aac_src_restart_adapter(dev,
816+ aac_src_check_health(dev), IOP_HWSOFT_RESET))
664817 goto error_iounmap;
665818 ++restart;
666819 }
@@ -701,7 +854,7 @@ int aac_src_init(struct aac_dev *dev) · 34 unmodified lines
701854 ? (startup_timeout - 60)
702855 : (startup_timeout / 2))))) {
703856 if (likely(!aac_src_restart_adapter(dev,
704− aac_src_check_health(dev))))
857+ aac_src_check_health(dev), IOP_HWSOFT_RESET)))
705858 start = jiffies;
706859 ++restart;
707860 }
@@ -798,7 +951,7 @@ int aac_srcv_init(struct aac_dev *dev) · 90 unmodified lines
798951 dev->a_ops.adapter_sync_cmd = src_sync_cmd;
799952 dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
800953 if ((aac_reset_devices || reset_devices) &&
801− !aac_src_restart_adapter(dev, 0))
954+ !aac_src_restart_adapter(dev, 0, IOP_HWSOFT_RESET))
802955 ++restart;
803956 /*
804957 * Check to see if flash update is running.
@@ -827,7 +980,8 @@ int aac_srcv_init(struct aac_dev *dev) · 22 unmodified lines
827980 */
828981 status = src_readl(dev, MUnit.OMR);
829982 if (status & KERNEL_PANIC) {
830− if (aac_src_restart_adapter(dev, aac_src_check_health(dev)))
983+ if (aac_src_restart_adapter(dev,
984+ aac_src_check_health(dev), IOP_HWSOFT_RESET))
831985 goto error_iounmap;
832986 ++restart;
833987 }
@@ -866,7 +1020,8 @@ int aac_srcv_init(struct aac_dev *dev) · 32 unmodified lines
8661020 ((startup_timeout > 60)
8671021 ? (startup_timeout - 60)
8681022 : (startup_timeout / 2))))) {
869− if (likely(!aac_src_restart_adapter(dev, aac_src_check_health(dev))))
1023+ if (likely(!aac_src_restart_adapter(dev,
1024+ aac_src_check_health(dev), IOP_HWSOFT_RESET)))
8701025 start = jiffies;
8711026 ++restart;
8721027 }
@@ -897,7 +1052,8 @@ int aac_srcv_init(struct aac_dev *dev) · 24 unmodified lines
8971052
8981053 if (aac_init_adapter(dev) == NULL)
8991054 goto error_iounmap;
900− if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE2)
1055+ if ((dev->comm_interface != AAC_COMM_MESSAGE_TYPE2) &&
1056+ (dev->comm_interface != AAC_COMM_MESSAGE_TYPE3))
9011057 goto error_iounmap;
9021058 if (dev->msi_enabled)
9031059 aac_src_access_devreg(dev, AAC_ENABLE_MSIX);
@@ -905,9 +1061,9 @@ int aac_srcv_init(struct aac_dev *dev) · 1 unmodified line
9051061 if (aac_acquire_irq(dev))
9061062 goto error_iounmap;
9071063
908− dev->dbg_base = dev->base_start;
909− dev->dbg_base_mapped = dev->base;
910− dev->dbg_size = dev->base_size;
1064+ dev->dbg_base = pci_resource_start(dev->pdev, 2);
1065+ dev->dbg_base_mapped = dev->regs.src.bar1;
1066+ dev->dbg_size = AAC_MIN_SRCV_BAR1_SIZE;
9111067 dev->a_ops.adapter_enable_int = aac_src_enable_interrupt_message;
9121068
9131069 aac_adapter_enable_int(dev);
drivers/scsi/atari_scsi.c+3−33
@@ -178,37 +178,6 @@ static int scsi_dma_is_ignored_buserr(unsigned char dma_stat) · 177 unmodified lines
178178 }
179179
180180
181−#if 0
182−/* Dead code... wasn't called anyway :-) and causes some trouble, because at
183− * end-of-DMA, both SCSI ints are triggered simultaneously, so the NCR int has
184− * to clear the DMA int pending bit before it allows other level 6 interrupts.
185− */
186−static void scsi_dma_buserr(int irq, void *dummy)
187−{
188− unsigned char dma_stat = tt_scsi_dma.dma_ctrl;
189−
190− /* Don't do anything if a NCR interrupt is pending. Probably it's just
191− * masked... */
192− if (atari_irq_pending(IRQ_TT_MFP_SCSI))
193− return;
194−
195− printk("Bad SCSI DMA interrupt! dma_addr=0x%08lx dma_stat=%02x dma_cnt=%08lx\n",
196− SCSI_DMA_READ_P(dma_addr), dma_stat, SCSI_DMA_READ_P(dma_cnt));
197− if (dma_stat & 0x80) {
198− if (!scsi_dma_is_ignored_buserr(dma_stat))
199− printk("SCSI DMA bus error -- bad DMA programming!\n");
200− } else {
201− /* Under normal circumstances we never should get to this point,
202− * since both interrupts are triggered simultaneously and the 5380
203− * int has higher priority. When this irq is handled, that DMA
204− * interrupt is cleared. So a warning message is printed here.
205− */
206− printk("SCSI DMA intr ?? -- this shouldn't happen!\n");
207− }
208−}
209−#endif
210−
211−
212181 static irqreturn_t scsi_tt_intr(int irq, void *dev)
213182 {
214183 struct Scsi_Host *instance = dev;
@@ -713,7 +682,8 @@ static int atari_scsi_bus_reset(struct scsi_cmnd *cmd) · 498 unmodified lines
713682 if (IS_A_TT()) {
714683 tt_scsi_dma.dma_ctrl = 0;
715684 } else {
716− st_dma.dma_mode_status = 0x90;
685+ if (stdma_is_locked_by(scsi_falcon_intr))
686+ st_dma.dma_mode_status = 0x90;
717687 atari_dma_active = 0;
718688 atari_dma_orig_addr = NULL;
719689 }
@@ -813,7 +783,7 @@ static int __init atari_scsi_probe(struct platform_device *pdev) · 93 unmodified lines
813783 return -ENOMEM;
814784 }
815785 atari_dma_phys_buffer = atari_stram_to_phys(atari_dma_buffer);
816− atari_dma_orig_addr = 0;
786+ atari_dma_orig_addr = NULL;
817787 }
818788
819789 instance = scsi_host_alloc(&atari_scsi_template,
drivers/scsi/be2iscsi/be.h+0−3
@@ -84,7 +84,6 @@ static inline void queue_tail_inc(struct be_queue_info *q) · 83 unmodified lines
8484 /*ISCSI */
8585
8686 struct be_aic_obj { /* Adaptive interrupt coalescing (AIC) info */
87− bool enable;
8887 u32 min_eqd; /* in usecs */
8988 u32 max_eqd; /* in usecs */
9089 u32 prev_eqd; /* in usecs */
@@ -94,8 +93,6 @@ struct be_aic_obj { /* Adaptive interrupt coalescing (AIC) info */ · 3 unmodified lines
9493 };
9594
9695 struct be_eq_obj {
97− bool todo_mcc_cq;
98− bool todo_cq;
9996 u32 cq_count;
10097 struct be_queue_info q;
10198 struct beiscsi_hba *phba;
drivers/scsi/be2iscsi/be_cmds.c+22−19
@@ -676,10 +676,10 @@ void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len, · 675 unmodified lines
676676 bool embedded, u8 sge_cnt)
677677 {
678678 if (embedded)
679− wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
679+ wrb->emb_sgecnt_special |= MCC_WRB_EMBEDDED_MASK;
680680 else
681− wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
682− MCC_WRB_SGE_CNT_SHIFT;
681+ wrb->emb_sgecnt_special |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
682+ MCC_WRB_SGE_CNT_SHIFT;
683683 wrb->payload_length = payload_len;
684684 be_dws_cpu_to_le(wrb, 8);
685685 }
@@ -1599,7 +1599,7 @@ int beiscsi_cmd_function_reset(struct beiscsi_hba *phba) · 913 unmodified lines
15991599 {
16001600 struct be_ctrl_info *ctrl = &phba->ctrl;
16011601 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
1602− struct be_post_sgl_pages_req *req = embedded_payload(wrb);
1602+ struct be_post_sgl_pages_req *req;
16031603 int status;
16041604
16051605 mutex_lock(&ctrl->mbox_lock);
@@ -1700,31 +1700,34 @@ int beiscsi_cmd_iscsi_cleanup(struct beiscsi_hba *phba, unsigned short ulp) · 94 unmodified lines
17001700 struct be_ctrl_info *ctrl = &phba->ctrl;
17011701 struct iscsi_cleanup_req_v1 *req_v1;
17021702 struct iscsi_cleanup_req *req;
1703+ u16 hdr_ring_id, data_ring_id;
17031704 struct be_mcc_wrb *wrb;
17041705 int status;
17051706
17061707 mutex_lock(&ctrl->mbox_lock);
17071708 wrb = wrb_from_mbox(&ctrl->mbox_mem);
1708− req = embedded_payload(wrb);
1709− be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1710− be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1711− OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
17121709
1713− /**
1714− * TODO: Check with FW folks the chute value to be set.
1715− * For now, use the ULP_MASK as the chute value.
1716− */
1710+ hdr_ring_id = HWI_GET_DEF_HDRQ_ID(phba, ulp);
1711+ data_ring_id = HWI_GET_DEF_BUFQ_ID(phba, ulp);
17171712 if (is_chip_be2_be3r(phba)) {
1713+ req = embedded_payload(wrb);
1714+ be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1715+ be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1716+ OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
17181717 req->chute = (1 << ulp);
1719− req->hdr_ring_id = HWI_GET_DEF_HDRQ_ID(phba, ulp);
1720− req->data_ring_id = HWI_GET_DEF_BUFQ_ID(phba, ulp);
1718+ /* BE2/BE3 FW creates 8-bit ring id */
1719+ req->hdr_ring_id = hdr_ring_id;
1720+ req->data_ring_id = data_ring_id;
17211721 } else {
1722− req_v1 = (struct iscsi_cleanup_req_v1 *)req;
1722+ req_v1 = embedded_payload(wrb);
1723+ be_wrb_hdr_prepare(wrb, sizeof(*req_v1), true, 0);
1724+ be_cmd_hdr_prepare(&req_v1->hdr, CMD_SUBSYSTEM_ISCSI,
1725+ OPCODE_COMMON_ISCSI_CLEANUP,
1726+ sizeof(*req_v1));
17231727 req_v1->hdr.version = 1;
1724− req_v1->hdr_ring_id = cpu_to_le16(HWI_GET_DEF_HDRQ_ID(phba,
1725− ulp));
1726− req_v1->data_ring_id = cpu_to_le16(HWI_GET_DEF_BUFQ_ID(phba,
1727− ulp));
1728+ req_v1->chute = (1 << ulp);
1729+ req_v1->hdr_ring_id = cpu_to_le16(hdr_ring_id);
1730+ req_v1->data_ring_id = cpu_to_le16(data_ring_id);
17281731 }
17291732
17301733 status = be_mbox_notify(ctrl);
drivers/scsi/be2iscsi/be_cmds.h+9−8
@@ -31,10 +31,16 @@ struct be_sge { · 30 unmodified lines
3131 __le32 len;
3232 };
3333
34−#define MCC_WRB_SGE_CNT_SHIFT 3 /* bits 3 - 7 of dword 0 */
35−#define MCC_WRB_SGE_CNT_MASK 0x1F /* bits 3 - 7 of dword 0 */
3634 struct be_mcc_wrb {
37− u32 embedded; /* dword 0 */
35+ u32 emb_sgecnt_special; /* dword 0 */
36+ /* bits 0 - embedded */
37+ /* bits 1 - 2 reserved */
38+ /* bits 3 - 7 sge count */
39+ /* bits 8 - 23 reserved */
40+ /* bits 24 - 31 special */
41+#define MCC_WRB_EMBEDDED_MASK 1
42+#define MCC_WRB_SGE_CNT_SHIFT 3
43+#define MCC_WRB_SGE_CNT_MASK 0x1F
3844 u32 payload_length; /* dword 1 */
3945 u32 tag0; /* dword 2 */
4046 u32 tag1; /* dword 3 */
@@ -1133,11 +1139,6 @@ struct tcp_connect_and_offload_out { · 1092 unmodified lines
11331139
11341140 } __packed;
11351141
1136−struct be_mcc_wrb_context {
1137− struct MCC_WRB *wrb;
1138− int *users_final_status;
1139−} __packed;
1140−
11411142 #define DB_DEF_PDU_RING_ID_MASK 0x3FFF /* bits 0 - 13 */
11421143 #define DB_DEF_PDU_CQPROC_MASK 0x3FFF /* bits 16 - 29 */
11431144 #define DB_DEF_PDU_REARM_SHIFT 14
drivers/scsi/be2iscsi/be_iscsi.c+83−82
@@ -165,33 +165,6 @@ beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid) · 164 unmodified lines
165165 return cls_conn;
166166 }
167167
168−/**
169− * beiscsi_bindconn_cid - Bind the beiscsi_conn with phba connection table
170− * @beiscsi_conn: The pointer to beiscsi_conn structure
171− * @phba: The phba instance
172− * @cid: The cid to free
173− */
174−static int beiscsi_bindconn_cid(struct beiscsi_hba *phba,
175− struct beiscsi_conn *beiscsi_conn,
176− unsigned int cid)
177−{
178− uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
179−
180− if (phba->conn_table[cri_index]) {
181− beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
182− "BS_%d : Connection table already occupied. Detected clash\n");
183−
184− return -EINVAL;
185− } else {
186− beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
187− "BS_%d : phba->conn_table[%d]=%p(beiscsi_conn)\n",
188− cri_index, beiscsi_conn);
189−
190− phba->conn_table[cri_index] = beiscsi_conn;
191− }
192− return 0;
193−}
194−
195168 /**
196169 * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
197170 * @cls_session: pointer to iscsi cls session
@@ -212,6 +185,7 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, · 14 unmodified lines
212185 struct hwi_wrb_context *pwrb_context;
213186 struct beiscsi_endpoint *beiscsi_ep;
214187 struct iscsi_endpoint *ep;
188+ uint16_t cri_index;
215189
216190 ep = iscsi_lookup_endpoint(transport_fd);
217191 if (!ep)
@@ -229,20 +203,34 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, · 11 unmodified lines
229203
230204 return -EEXIST;
231205 }
232−
233− pwrb_context = &phwi_ctrlr->wrb_context[BE_GET_CRI_FROM_CID(
234− beiscsi_ep->ep_cid)];
206+ cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid);
207+ if (phba->conn_table[cri_index]) {
208+ if (beiscsi_conn != phba->conn_table[cri_index] ||
209+ beiscsi_ep != phba->conn_table[cri_index]->ep) {
210+ __beiscsi_log(phba, KERN_ERR,
211+ "BS_%d : conn_table not empty at %u: cid %u conn %p:%p\n",
212+ cri_index,
213+ beiscsi_ep->ep_cid,
214+ beiscsi_conn,
215+ phba->conn_table[cri_index]);
216+ return -EINVAL;
217+ }
218+ }
235219
236220 beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
237221 beiscsi_conn->ep = beiscsi_ep;
238222 beiscsi_ep->conn = beiscsi_conn;
223+ /**
224+ * Each connection is associated with a WRBQ kept in wrb_context.
225+ * Store doorbell offset for transmit path.
226+ */
227+ pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
239228 beiscsi_conn->doorbell_offset = pwrb_context->doorbell_offset;
240−
241229 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
242− "BS_%d : beiscsi_conn=%p conn=%p ep_cid=%d\n",
243− beiscsi_conn, conn, beiscsi_ep->ep_cid);
244−
245− return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid);
230+ "BS_%d : cid %d phba->conn_table[%u]=%p\n",
231+ beiscsi_ep->ep_cid, cri_index, beiscsi_conn);
232+ phba->conn_table[cri_index] = beiscsi_conn;
233+ return 0;
246234 }
247235
248236 static int beiscsi_iface_create_ipv4(struct beiscsi_hba *phba)
@@ -973,9 +961,9 @@ int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn) · 724 unmodified lines
973961 */
974962 static int beiscsi_get_cid(struct beiscsi_hba *phba)
975963 {
976− unsigned short cid = 0xFFFF, cid_from_ulp;
977− struct ulp_cid_info *cid_info = NULL;
978964 uint16_t cid_avlbl_ulp0, cid_avlbl_ulp1;
965+ unsigned short cid, cid_from_ulp;
966+ struct ulp_cid_info *cid_info;
979967
980968 /* Find the ULP which has more CID available */
981969 cid_avlbl_ulp0 = (phba->cid_array_info[BEISCSI_ULP0]) ?
@@ -984,20 +972,27 @@ static int beiscsi_get_cid(struct beiscsi_hba *phba) · 2 unmodified lines
984972 BEISCSI_ULP1_AVLBL_CID(phba) : 0;
985973 cid_from_ulp = (cid_avlbl_ulp0 > cid_avlbl_ulp1) ?
986974 BEISCSI_ULP0 : BEISCSI_ULP1;
987−
988− if (test_bit(cid_from_ulp, (void *)&phba->fw_config.ulp_supported)) {
989− cid_info = phba->cid_array_info[cid_from_ulp];
990− if (!cid_info->avlbl_cids)
991− return cid;
992−
993− cid = cid_info->cid_array[cid_info->cid_alloc++];
994−
995− if (cid_info->cid_alloc == BEISCSI_GET_CID_COUNT(
996− phba, cid_from_ulp))
997− cid_info->cid_alloc = 0;
998−
999− cid_info->avlbl_cids--;
975+ /**
976+ * If iSCSI protocol is loaded only on ULP 0, and when cid_avlbl_ulp
977+ * is ZERO for both, ULP 1 is returned.
978+ * Check if ULP is loaded before getting new CID.
979+ */
980+ if (!test_bit(cid_from_ulp, (void *)&phba->fw_config.ulp_supported))
981+ return BE_INVALID_CID;
982+
983+ cid_info = phba->cid_array_info[cid_from_ulp];
984+ cid = cid_info->cid_array[cid_info->cid_alloc];
985+ if (!cid_info->avlbl_cids || cid == BE_INVALID_CID) {
986+ __beiscsi_log(phba, KERN_ERR,
987+ "BS_%d : failed to get cid: available %u:%u\n",
988+ cid_info->avlbl_cids, cid_info->cid_free);
989+ return BE_INVALID_CID;
1000990 }
991+ /* empty the slot */
992+ cid_info->cid_array[cid_info->cid_alloc++] = BE_INVALID_CID;
993+ if (cid_info->cid_alloc == BEISCSI_GET_CID_COUNT(phba, cid_from_ulp))
994+ cid_info->cid_alloc = 0;
995+ cid_info->avlbl_cids--;
1001996 return cid;
1002997 }
1003998
@@ -1008,22 +1003,28 @@ static int beiscsi_get_cid(struct beiscsi_hba *phba) · 4 unmodified lines
10081003 */
10091004 static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
10101005 {
1011− uint16_t cid_post_ulp;
1012− struct hwi_controller *phwi_ctrlr;
1013− struct hwi_wrb_context *pwrb_context;
1014− struct ulp_cid_info *cid_info = NULL;
10151006 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
1007+ struct hwi_wrb_context *pwrb_context;
1008+ struct hwi_controller *phwi_ctrlr;
1009+ struct ulp_cid_info *cid_info;
1010+ uint16_t cid_post_ulp;
10161011
10171012 phwi_ctrlr = phba->phwi_ctrlr;
10181013 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
10191014 cid_post_ulp = pwrb_context->ulp_num;
10201015
10211016 cid_info = phba->cid_array_info[cid_post_ulp];
1022− cid_info->avlbl_cids++;
1023−
1017+ /* fill only in empty slot */
1018+ if (cid_info->cid_array[cid_info->cid_free] != BE_INVALID_CID) {
1019+ __beiscsi_log(phba, KERN_ERR,
1020+ "BS_%d : failed to put cid %u: available %u:%u\n",
1021+ cid, cid_info->avlbl_cids, cid_info->cid_free);
1022+ return;
1023+ }
10241024 cid_info->cid_array[cid_info->cid_free++] = cid;
10251025 if (cid_info->cid_free == BEISCSI_GET_CID_COUNT(phba, cid_post_ulp))
10261026 cid_info->cid_free = 0;
1027+ cid_info->avlbl_cids++;
10271028 }
10281029
10291030 /**
@@ -1037,8 +1038,8 @@ static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep) · 7 unmodified lines
10371038
10381039 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
10391040 beiscsi_ep->phba = NULL;
1040− phba->ep_array[BE_GET_CRI_FROM_CID
1041− (beiscsi_ep->ep_cid)] = NULL;
1041+ /* clear this to track freeing in beiscsi_ep_disconnect */
1042+ phba->ep_array[BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid)] = NULL;
10421043
10431044 /**
10441045 * Check if any connection resource allocated by driver
@@ -1049,6 +1050,11 @@ static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep) · 4 unmodified lines
10491050 return;
10501051
10511052 beiscsi_conn = beiscsi_ep->conn;
1053+ /**
1054+ * Break ep->conn link here so that completions after
1055+ * this are ignored.
1056+ */
1057+ beiscsi_ep->conn = NULL;
10521058 if (beiscsi_conn->login_in_progress) {
10531059 beiscsi_free_mgmt_task_handles(beiscsi_conn,
10541060 beiscsi_conn->task);
@@ -1079,7 +1085,7 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep, · 24 unmodified lines
10791085 "BS_%d : In beiscsi_open_conn\n");
10801086
10811087 beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
1082− if (beiscsi_ep->ep_cid == 0xFFFF) {
1088+ if (beiscsi_ep->ep_cid == BE_INVALID_CID) {
10831089 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
10841090 "BS_%d : No free cid available\n");
10851091 return ret;
@@ -1114,7 +1120,7 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep, · 28 unmodified lines
11141120 nonemb_cmd.size = req_memsize;
11151121 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
11161122 tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
1117− if (tag <= 0) {
1123+ if (!tag) {
11181124 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
11191125 "BS_%d : mgmt_open_connection Failed for cid=%d\n",
11201126 beiscsi_ep->ep_cid);
@@ -1284,26 +1290,6 @@ static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag) · 163 unmodified lines
12841290 return ret;
12851291 }
12861292
1287−/**
1288− * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
1289− * @phba: The phba instance
1290− * @cid: The cid to free
1291− */
1292−static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
1293− unsigned int cid)
1294−{
1295− uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
1296−
1297− if (phba->conn_table[cri_index])
1298− phba->conn_table[cri_index] = NULL;
1299− else {
1300− beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1301− "BS_%d : Connection table Not occupied.\n");
1302− return -EINVAL;
1303− }
1304− return 0;
1305−}
1306−
13071293 /**
13081294 * beiscsi_ep_disconnect - Tears down the TCP connection
13091295 * @ep: endpoint to be used
@@ -1318,13 +1304,23 @@ void beiscsi_ep_disconnect(struct iscsi_endpoint *ep) · 8 unmodified lines
13181304 unsigned int tag;
13191305 uint8_t mgmt_invalidate_flag, tcp_upload_flag;
13201306 unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
1307+ uint16_t cri_index;
13211308
13221309 beiscsi_ep = ep->dd_data;
13231310 phba = beiscsi_ep->phba;
13241311 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1325− "BS_%d : In beiscsi_ep_disconnect for ep_cid = %d\n",
1312+ "BS_%d : In beiscsi_ep_disconnect for ep_cid = %u\n",
13261313 beiscsi_ep->ep_cid);
13271314
1315+ cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid);
1316+ if (!phba->ep_array[cri_index]) {
1317+ __beiscsi_log(phba, KERN_ERR,
1318+ "BS_%d : ep_array at %u cid %u empty\n",
1319+ cri_index,
1320+ beiscsi_ep->ep_cid);
1321+ return;
1322+ }
1323+
13281324 if (beiscsi_ep->conn) {
13291325 beiscsi_conn = beiscsi_ep->conn;
13301326 iscsi_suspend_queue(beiscsi_conn->conn);
@@ -1356,7 +1352,12 @@ void beiscsi_ep_disconnect(struct iscsi_endpoint *ep) · 25 unmodified lines
13561352 free_ep:
13571353 msleep(BEISCSI_LOGOUT_SYNC_DELAY);
13581354 beiscsi_free_ep(beiscsi_ep);
1359− beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
1355+ if (!phba->conn_table[cri_index])
1356+ __beiscsi_log(phba, KERN_ERR,
1357+ "BS_%d : conn_table empty at %u: cid %u\n",
1358+ cri_index,
1359+ beiscsi_ep->ep_cid);
1360+ phba->conn_table[cri_index] = NULL;
13601361 iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
13611362 }
13621363
drivers/scsi/be2iscsi/be_main.c+157−188
@@ -67,8 +67,6 @@ beiscsi_##_name##_disp(struct device *dev,\ · 66 unmodified lines
6767 { \
6868 struct Scsi_Host *shost = class_to_shost(dev);\
6969 struct beiscsi_hba *phba = iscsi_host_priv(shost); \
70− uint32_t param_val = 0; \
71− param_val = phba->attr_##_name;\
7270 return snprintf(buf, PAGE_SIZE, "%d\n",\
7371 phba->attr_##_name);\
7472 }
@@ -218,160 +216,156 @@ static int beiscsi_slave_configure(struct scsi_device *sdev) · 143 unmodified lines
218216
219217 static int beiscsi_eh_abort(struct scsi_cmnd *sc)
220218 {
219+ struct iscsi_task *abrt_task = (struct iscsi_task *)sc->SCp.ptr;
221220 struct iscsi_cls_session *cls_session;
222− struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
223− struct beiscsi_io_task *aborted_io_task;
224− struct iscsi_conn *conn;
221+ struct beiscsi_io_task *abrt_io_task;
225222 struct beiscsi_conn *beiscsi_conn;
226− struct beiscsi_hba *phba;
227223 struct iscsi_session *session;
228− struct invalidate_command_table *inv_tbl;
229− struct be_dma_mem nonemb_cmd;
230− unsigned int cid, tag, num_invalidate;
224+ struct invldt_cmd_tbl inv_tbl;
225+ struct beiscsi_hba *phba;
226+ struct iscsi_conn *conn;
231227 int rc;
232228
233229 cls_session = starget_to_session(scsi_target(sc->device));
234230 session = cls_session->dd_data;
235231
236− spin_lock_bh(&session->frwd_lock);
237− if (!aborted_task || !aborted_task->sc) {
238− /* we raced */
239− spin_unlock_bh(&session->frwd_lock);
240− return SUCCESS;
241− }
242−
243− aborted_io_task = aborted_task->dd_data;
244− if (!aborted_io_task->scsi_cmnd) {
245− /* raced or invalid command */
246− spin_unlock_bh(&session->frwd_lock);
232+ /* check if we raced, task just got cleaned up under us */
233+ spin_lock_bh(&session->back_lock);
234+ if (!abrt_task || !abrt_task->sc) {
235+ spin_unlock_bh(&session->back_lock);
247236 return SUCCESS;
248237 }
249− spin_unlock_bh(&session->frwd_lock);
250− /* Invalidate WRB Posted for this Task */
251− AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
252− aborted_io_task->pwrb_handle->pwrb,
253− 1);
254−
255− conn = aborted_task->conn;
238+ /* get a task ref till FW processes the req for the ICD used */
239+ __iscsi_get_task(abrt_task);
240+ abrt_io_task = abrt_task->dd_data;
241+ conn = abrt_task->conn;
256242 beiscsi_conn = conn->dd_data;
257243 phba = beiscsi_conn->phba;
258−
259− /* invalidate iocb */
260− cid = beiscsi_conn->beiscsi_conn_cid;
261− inv_tbl = phba->inv_tbl;
262− memset(inv_tbl, 0x0, sizeof(*inv_tbl));
263− inv_tbl->cid = cid;
264− inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
265− num_invalidate = 1;
266− nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
267− sizeof(struct invalidate_commands_params_in),
268− &nonemb_cmd.dma);
269− if (nonemb_cmd.va == NULL) {
270− beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
271− "BM_%d : Failed to allocate memory for"
272− "mgmt_invalidate_icds\n");
273− return FAILED;
244+ /* mark WRB invalid which have been not processed by FW yet */
245+ if (is_chip_be2_be3r(phba)) {
246+ AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
247+ abrt_io_task->pwrb_handle->pwrb, 1);
248+ } else {
249+ AMAP_SET_BITS(struct amap_iscsi_wrb_v2, invld,
250+ abrt_io_task->pwrb_handle->pwrb, 1);
274251 }
275− nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
252+ inv_tbl.cid = beiscsi_conn->beiscsi_conn_cid;
253+ inv_tbl.icd = abrt_io_task->psgl_handle->sgl_index;
254+ spin_unlock_bh(&session->back_lock);
276255
277− tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
278− cid, &nonemb_cmd);
279− if (!tag) {
256+ rc = beiscsi_mgmt_invalidate_icds(phba, &inv_tbl, 1);
257+ iscsi_put_task(abrt_task);
258+ if (rc) {
280259 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
281− "BM_%d : mgmt_invalidate_icds could not be"
282− "submitted\n");
283− pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
284− nonemb_cmd.va, nonemb_cmd.dma);
285−
260+ "BM_%d : sc %p invalidation failed %d\n",
261+ sc, rc);
286262 return FAILED;
287263 }
288264
289− rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd);
290− if (rc != -EBUSY)
291− pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
292− nonemb_cmd.va, nonemb_cmd.dma);
293−
294265 return iscsi_eh_abort(sc);
295266 }
296267
297268 static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
298269 {
299− struct iscsi_task *abrt_task;
300− struct beiscsi_io_task *abrt_io_task;
301− struct iscsi_conn *conn;
270+ struct beiscsi_invldt_cmd_tbl {
271+ struct invldt_cmd_tbl tbl[BE_INVLDT_CMD_TBL_SZ];
272+ struct iscsi_task *task[BE_INVLDT_CMD_TBL_SZ];
273+ } *inv_tbl;
274+ struct iscsi_cls_session *cls_session;
302275 struct beiscsi_conn *beiscsi_conn;
303− struct beiscsi_hba *phba;
276+ struct beiscsi_io_task *io_task;
304277 struct iscsi_session *session;
305− struct iscsi_cls_session *cls_session;
306− struct invalidate_command_table *inv_tbl;
307− struct be_dma_mem nonemb_cmd;
308− unsigned int cid, tag, i, num_invalidate;
309− int rc;
278+ struct beiscsi_hba *phba;
279+ struct iscsi_conn *conn;
280+ struct iscsi_task *task;
281+ unsigned int i, nents;
282+ int rc, more = 0;
310283
311− /* invalidate iocbs */
312284 cls_session = starget_to_session(scsi_target(sc->device));
313285 session = cls_session->dd_data;
286+
314287 spin_lock_bh(&session->frwd_lock);
315288 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
316289 spin_unlock_bh(&session->frwd_lock);
317290 return FAILED;
318291 }
292+
319293 conn = session->leadconn;
320294 beiscsi_conn = conn->dd_data;
321295 phba = beiscsi_conn->phba;
322− cid = beiscsi_conn->beiscsi_conn_cid;
323− inv_tbl = phba->inv_tbl;
324− memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
325− num_invalidate = 0;
296+
297+ inv_tbl = kzalloc(sizeof(*inv_tbl), GFP_ATOMIC);
298+ if (!inv_tbl) {
299+ spin_unlock_bh(&session->frwd_lock);
300+ beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
301+ "BM_%d : invldt_cmd_tbl alloc failed\n");
302+ return FAILED;
303+ }
304+ nents = 0;
305+ /* take back_lock to prevent task from getting cleaned up under us */
306+ spin_lock(&session->back_lock);
326307 for (i = 0; i < conn->session->cmds_max; i++) {
327− abrt_task = conn->session->cmds[i];
328− abrt_io_task = abrt_task->dd_data;
329− if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
308+ task = conn->session->cmds[i];
309+ if (!task->sc)
330310 continue;
331311
332− if (sc->device->lun != abrt_task->sc->device->lun)
312+ if (sc->device->lun != task->sc->device->lun)
333313 continue;
314+ /**
315+ * Can't fit in more cmds? Normally this won't happen b'coz
316+ * BEISCSI_CMD_PER_LUN is same as BE_INVLDT_CMD_TBL_SZ.
317+ */
318+ if (nents == BE_INVLDT_CMD_TBL_SZ) {
319+ more = 1;
320+ break;
321+ }
334322
335− /* Invalidate WRB Posted for this Task */
336− AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
337− abrt_io_task->pwrb_handle->pwrb,
338− 1);
323+ /* get a task ref till FW processes the req for the ICD used */
324+ __iscsi_get_task(task);
325+ io_task = task->dd_data;
326+ /* mark WRB invalid which have been not processed by FW yet */
327+ if (is_chip_be2_be3r(phba)) {
328+ AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
329+ io_task->pwrb_handle->pwrb, 1);
330+ } else {
331+ AMAP_SET_BITS(struct amap_iscsi_wrb_v2, invld,
332+ io_task->pwrb_handle->pwrb, 1);
333+ }
339334
340− inv_tbl->cid = cid;
341− inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
342− num_invalidate++;
343− inv_tbl++;
335+ inv_tbl->tbl[nents].cid = beiscsi_conn->beiscsi_conn_cid;
336+ inv_tbl->tbl[nents].icd = io_task->psgl_handle->sgl_index;
337+ inv_tbl->task[nents] = task;
338+ nents++;
344339 }
340+ spin_unlock_bh(&session->back_lock);
345341 spin_unlock_bh(&session->frwd_lock);
346− inv_tbl = phba->inv_tbl;
347342
348− nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
349− sizeof(struct invalidate_commands_params_in),
350− &nonemb_cmd.dma);
351− if (nonemb_cmd.va == NULL) {
343+ rc = SUCCESS;
344+ if (!nents)
345+ goto end_reset;
346+
347+ if (more) {
352348 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
353− "BM_%d : Failed to allocate memory for"
354− "mgmt_invalidate_icds\n");
355− return FAILED;
349+ "BM_%d : number of cmds exceeds size of invalidation table\n");
350+ rc = FAILED;
351+ goto end_reset;
356352 }
357− nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
358− memset(nonemb_cmd.va, 0, nonemb_cmd.size);
359− tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
360− cid, &nonemb_cmd);
361− if (!tag) {
353+
354+ if (beiscsi_mgmt_invalidate_icds(phba, &inv_tbl->tbl[0], nents)) {
362355 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
363− "BM_%d : mgmt_invalidate_icds could not be"
364− " submitted\n");
365− pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
366− nonemb_cmd.va, nonemb_cmd.dma);
367− return FAILED;
356+ "BM_%d : cid %u scmds invalidation failed\n",
357+ beiscsi_conn->beiscsi_conn_cid);
358+ rc = FAILED;
368359 }
369360
370− rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd);
371− if (rc != -EBUSY)
372− pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
373− nonemb_cmd.va, nonemb_cmd.dma);
374− return iscsi_eh_device_reset(sc);
361+end_reset:
362+ for (i = 0; i < nents; i++)
363+ iscsi_put_task(inv_tbl->task[i]);
364+ kfree(inv_tbl);
365+
366+ if (rc == SUCCESS)
367+ rc = iscsi_eh_device_reset(sc);
368+ return rc;
375369 }
376370
377371 /*------------------- PCI Driver operations and data ----------------- */
@@ -395,6 +389,7 @@ static struct scsi_host_template beiscsi_sht = { · 17 unmodified lines
395389 .change_queue_depth = scsi_change_queue_depth,
396390 .slave_configure = beiscsi_slave_configure,
397391 .target_alloc = iscsi_target_alloc,
392+ .eh_timed_out = iscsi_eh_cmd_timed_out,
398393 .eh_abort_handler = beiscsi_eh_abort,
399394 .eh_device_reset_handler = beiscsi_eh_device_reset,
400395 .eh_target_reset_handler = iscsi_eh_session_reset,
@@ -646,7 +641,6 @@ static void beiscsi_get_params(struct beiscsi_hba *phba) · 245 unmodified lines
646641 phba->params.num_sge_per_io = BE2_SGE;
647642 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
648643 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
649− phba->params.eq_timer = 64;
650644 phba->params.num_eq_entries = 1024;
651645 phba->params.num_cq_entries = 1024;
652646 phba->params.wrbs_per_cxn = 256;
@@ -964,6 +958,10 @@ beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context, · 311 unmodified lines
964958 unsigned long flags;
965959
966960 spin_lock_irqsave(&pwrb_context->wrb_lock, flags);
961+ if (!pwrb_context->wrb_handles_available) {
962+ spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags);
963+ return NULL;
964+ }
967965 pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index];
968966 pwrb_context->wrb_handles_available--;
969967 if (pwrb_context->alloc_index == (wrbs_per_cxn - 1))
@@ -1014,6 +1012,7 @@ beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context, · 44 unmodified lines
10141012 pwrb_context->free_index = 0;
10151013 else
10161014 pwrb_context->free_index++;
1015+ pwrb_handle->pio_handle = NULL;
10171016 spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags);
10181017 }
10191018
@@ -1224,6 +1223,7 @@ hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn, · 204 unmodified lines
12241223 uint16_t wrb_index, cid, cri_index;
12251224 struct hwi_controller *phwi_ctrlr;
12261225 struct wrb_handle *pwrb_handle;
1226+ struct iscsi_session *session;
12271227 struct iscsi_task *task;
12281228
12291229 phwi_ctrlr = phba->phwi_ctrlr;
@@ -1242,8 +1242,12 @@ hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn, · 12 unmodified lines
12421242 cri_index = BE_GET_CRI_FROM_CID(cid);
12431243 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
12441244 pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index];
1245+ session = beiscsi_conn->conn->session;
1246+ spin_lock_bh(&session->back_lock);
12451247 task = pwrb_handle->pio_handle;
1246− iscsi_put_task(task);
1248+ if (task)
1249+ __iscsi_put_task(task);
1250+ spin_unlock_bh(&session->back_lock);
12471251 }
12481252
12491253 static void
@@ -1323,16 +1327,15 @@ static void adapter_get_sol_cqe(struct beiscsi_hba *phba, · 73 unmodified lines
13231327 static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
13241328 struct beiscsi_hba *phba, struct sol_cqe *psol)
13251329 {
1326− struct hwi_wrb_context *pwrb_context;
1327− struct wrb_handle *pwrb_handle;
1328− struct iscsi_wrb *pwrb = NULL;
1329− struct hwi_controller *phwi_ctrlr;
1330− struct iscsi_task *task;
1331− unsigned int type;
13321330 struct iscsi_conn *conn = beiscsi_conn->conn;
13331331 struct iscsi_session *session = conn->session;
13341332 struct common_sol_cqe csol_cqe = {0};
1333+ struct hwi_wrb_context *pwrb_context;
1334+ struct hwi_controller *phwi_ctrlr;
1335+ struct wrb_handle *pwrb_handle;
1336+ struct iscsi_task *task;
13351337 uint16_t cri_index = 0;
1338+ uint8_t type;
13361339
13371340 phwi_ctrlr = phba->phwi_ctrlr;
13381341
@@ -1345,11 +1348,14 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, · 6 unmodified lines
13451348 pwrb_handle = pwrb_context->pwrb_handle_basestd[
13461349 csol_cqe.wrb_index];
13471350
1351+ spin_lock_bh(&session->back_lock);
13481352 task = pwrb_handle->pio_handle;
1349− pwrb = pwrb_handle->pwrb;
1353+ if (!task) {
1354+ spin_unlock_bh(&session->back_lock);
1355+ return;
1356+ }
13501357 type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type;
13511358
1352− spin_lock_bh(&session->back_lock);
13531359 switch (type) {
13541360 case HWH_TYPE_IO:
13551361 case HWH_TYPE_IO_RD:
@@ -1711,13 +1717,12 @@ beiscsi_hdq_post_handles(struct beiscsi_hba *phba, · 355 unmodified lines
17111717 struct list_head *hfree_list;
17121718 struct phys_addr *pasync_sge;
17131719 u32 ring_id, doorbell = 0;
1714− u16 index, num_entries;
17151720 u32 doorbell_offset;
17161721 u16 prod = 0, cons;
1722+ u16 index;
17171723
17181724 phwi_ctrlr = phba->phwi_ctrlr;
17191725 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num);
1720− num_entries = pasync_ctx->num_entries;
17211726 if (header) {
17221727 cons = pasync_ctx->async_header.free_entries;
17231728 hfree_list = &pasync_ctx->async_header.free_list;
@@ -2374,13 +2379,10 @@ static int hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task) · 650 unmodified lines
23742379 static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
23752380 {
23762381 uint8_t mem_descr_index, ulp_num;
2377− unsigned int num_cq_pages, num_async_pdu_buf_pages;
2382+ unsigned int num_async_pdu_buf_pages;
23782383 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
23792384 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
23802385
2381− num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2382− sizeof(struct sol_cqe));
2383−
23842386 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
23852387
23862388 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
@@ -2737,7 +2739,7 @@ static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba) · 350 unmodified lines
27372739
27382740 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
27392741 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
2740− /* get async_ctx for each ULP */
2742+ /* get async_ctx for each ULP */
27412743 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
27422744 mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
27432745 (ulp_num * MEM_DESCR_OFFSET));
@@ -3367,7 +3369,7 @@ beiscsi_create_wrb_rings(struct beiscsi_hba *phba, · 623 unmodified lines
33673369 struct hwi_context_memory *phwi_context,
33683370 struct hwi_controller *phwi_ctrlr)
33693371 {
3370− unsigned int wrb_mem_index, offset, size, num_wrb_rings;
3372+ unsigned int num_wrb_rings;
33713373 u64 pa_addr_lo;
33723374 unsigned int idx, num, i, ulp_num;
33733375 struct mem_array *pwrb_arr;
@@ -3432,10 +3434,6 @@ beiscsi_create_wrb_rings(struct beiscsi_hba *phba, · 58 unmodified lines
34323434 }
34333435
34343436 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3435− wrb_mem_index = 0;
3436− offset = 0;
3437− size = 0;
3438−
34393437 if (ulp_count > 1) {
34403438 ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT;
34413439
@@ -3663,7 +3661,6 @@ static void hwi_cleanup_port(struct beiscsi_hba *phba) · 221 unmodified lines
36633661 struct be_ctrl_info *ctrl = &phba->ctrl;
36643662 struct hwi_controller *phwi_ctrlr;
36653663 struct hwi_context_memory *phwi_context;
3666− struct hd_async_context *pasync_ctx;
36673664 int i, eq_for_mcc, ulp_num;
36683665
36693666 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
@@ -3700,8 +3697,6 @@ static void hwi_cleanup_port(struct beiscsi_hba *phba) · 30 unmodified lines
37003697 q = &phwi_context->be_def_dataq[ulp_num];
37013698 if (q->created)
37023699 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3703−
3704− pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
37053700 }
37063701 }
37073702
@@ -3804,7 +3799,6 @@ static int hwi_init_port(struct beiscsi_hba *phba) · 96 unmodified lines
38043799 /**
38053800 * Now that the default PDU rings have been created,
38063801 * let EP know about it.
3807− * Call beiscsi_cmd_iscsi_cleanup before posting?
38083802 */
38093803 beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_HDR,
38103804 ulp_num);
@@ -3850,14 +3844,6 @@ static int hwi_init_port(struct beiscsi_hba *phba) · 39 unmodified lines
38503844 phwi_ctrlr->wrb_context[cri].cid] =
38513845 async_arr_idx++;
38523846 }
3853− /**
3854− * Now that the default PDU rings have been created,
3855− * let EP know about it.
3856− */
3857− beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_HDR,
3858− ulp_num);
3859− beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_DATA,
3860− ulp_num);
38613847 }
38623848 }
38633849
@@ -3934,31 +3920,6 @@ static void beiscsi_free_mem(struct beiscsi_hba *phba) · 70 unmodified lines
39343920 kfree(phba->phwi_ctrlr);
39353921 }
39363922
3937−static int beiscsi_init_controller(struct beiscsi_hba *phba)
3938−{
3939− int ret = -ENOMEM;
3940−
3941− ret = beiscsi_get_memory(phba);
3942− if (ret < 0) {
3943− beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3944− "BM_%d : beiscsi_dev_probe -"
3945− "Failed in beiscsi_alloc_memory\n");
3946− return ret;
3947− }
3948−
3949− ret = hwi_init_controller(phba);
3950− if (ret)
3951− goto free_init;
3952− beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3953− "BM_%d : Return success from beiscsi_init_controller");
3954−
3955− return 0;
3956−
3957−free_init:
3958− beiscsi_free_mem(phba);
3959− return ret;
3960−}
3961−
39623923 static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
39633924 {
39643925 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
@@ -4089,9 +4050,10 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phba) · 124 unmodified lines
40894050 }
40904051
40914052 /* Allocate memory for CID array */
4092− ptr_cid_info->cid_array = kzalloc(sizeof(void *) *
4093− BEISCSI_GET_CID_COUNT(phba,
4094− ulp_num), GFP_KERNEL);
4053+ ptr_cid_info->cid_array =
4054+ kcalloc(BEISCSI_GET_CID_COUNT(phba, ulp_num),
4055+ sizeof(*ptr_cid_info->cid_array),
4056+ GFP_KERNEL);
40954057 if (!ptr_cid_info->cid_array) {
40964058 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
40974059 "BM_%d : Failed to allocate memory"
@@ -4231,33 +4193,30 @@ static int beiscsi_init_port(struct beiscsi_hba *phba) · 133 unmodified lines
42314193 {
42324194 int ret;
42334195
4234− ret = beiscsi_init_controller(phba);
4196+ ret = hwi_init_controller(phba);
42354197 if (ret < 0) {
42364198 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4237− "BM_%d : beiscsi_dev_probe - Failed in"
4238− "beiscsi_init_controller\n");
4199+ "BM_%d : init controller failed\n");
42394200 return ret;
42404201 }
42414202 ret = beiscsi_init_sgl_handle(phba);
42424203 if (ret < 0) {
42434204 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4244− "BM_%d : beiscsi_dev_probe - Failed in"
4245− "beiscsi_init_sgl_handle\n");
4246− goto do_cleanup_ctrlr;
4205+ "BM_%d : init sgl handles failed\n");
4206+ goto cleanup_port;
42474207 }
42484208
42494209 ret = hba_setup_cid_tbls(phba);
42504210 if (ret < 0) {
42514211 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4252− "BM_%d : Failed in hba_setup_cid_tbls\n");
4212+ "BM_%d : setup CID table failed\n");
42534213 kfree(phba->io_sgl_hndl_base);
42544214 kfree(phba->eh_sgl_hndl_base);
4255− goto do_cleanup_ctrlr;
4215+ goto cleanup_port;
42564216 }
4257−
42584217 return ret;
42594218
4260−do_cleanup_ctrlr:
4219+cleanup_port:
42614220 hwi_cleanup_port(phba);
42624221 return ret;
42634222 }
@@ -5417,10 +5376,10 @@ static int beiscsi_enable_port(struct beiscsi_hba *phba) · 1153 unmodified lines
54175376
54185377 phba->shost->max_id = phba->params.cxns_per_ctrl;
54195378 phba->shost->can_queue = phba->params.ios_per_ctrl;
5420− ret = hwi_init_controller(phba);
5421− if (ret) {
5379+ ret = beiscsi_init_port(phba);
5380+ if (ret < 0) {
54225381 __beiscsi_log(phba, KERN_ERR,
5423− "BM_%d : init controller failed %d\n", ret);
5382+ "BM_%d : init port failed\n");
54245383 goto disable_msix;
54255384 }
54265385
@@ -5526,6 +5485,7 @@ static void beiscsi_disable_port(struct beiscsi_hba *phba, int unload) · 99 unmodified lines
55265485 cancel_work_sync(&pbe_eq->mcc_work);
55275486 }
55285487 hwi_cleanup_port(phba);
5488+ beiscsi_cleanup_port(phba);
55295489 }
55305490
55315491 static void beiscsi_sess_work(struct work_struct *work)
@@ -5638,11 +5598,12 @@ static void beiscsi_eeh_resume(struct pci_dev *pdev) · 106 unmodified lines
56385598 static int beiscsi_dev_probe(struct pci_dev *pcidev,
56395599 const struct pci_device_id *id)
56405600 {
5641− struct beiscsi_hba *phba = NULL;
5642− struct hwi_controller *phwi_ctrlr;
56435601 struct hwi_context_memory *phwi_context;
5602+ struct hwi_controller *phwi_ctrlr;
5603+ struct beiscsi_hba *phba = NULL;
56445604 struct be_eq_obj *pbe_eq;
56455605 unsigned int s_handle;
5606+ char wq_name[20];
56465607 int ret, i;
56475608
56485609 ret = beiscsi_enable_pci(pcidev);
@@ -5680,6 +5641,8 @@ static int beiscsi_dev_probe(struct pci_dev *pcidev, · 31 unmodified lines
56805641 case OC_DEVICE_ID2:
56815642 phba->generation = BE_GEN2;
56825643 phba->iotask_fn = beiscsi_iotask;
5644+ dev_warn(&pcidev->dev,
5645+ "Obsolete/Unsupported BE2 Adapter Family\n");
56835646 break;
56845647 case BE_DEVICE_ID2:
56855648 case OC_DEVICE_ID3:
@@ -5735,11 +5698,18 @@ static int beiscsi_dev_probe(struct pci_dev *pcidev, · 49 unmodified lines
57355698
57365699 phba->shost->max_id = phba->params.cxns_per_ctrl;
57375700 phba->shost->can_queue = phba->params.ios_per_ctrl;
5701+ ret = beiscsi_get_memory(phba);
5702+ if (ret < 0) {
5703+ beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5704+ "BM_%d : alloc host mem failed\n");
5705+ goto free_port;
5706+ }
5707+
57385708 ret = beiscsi_init_port(phba);
57395709 if (ret < 0) {
57405710 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5741− "BM_%d : beiscsi_dev_probe-"
5742− "Failed in beiscsi_init_port\n");
5711+ "BM_%d : init port failed\n");
5712+ beiscsi_free_mem(phba);
57435713 goto free_port;
57445714 }
57455715
@@ -5754,9 +5724,9 @@ static int beiscsi_dev_probe(struct pci_dev *pcidev, · 8 unmodified lines
57545724
57555725 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
57565726
5757− snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
5727+ snprintf(wq_name, sizeof(wq_name), "beiscsi_%02x_wq",
57585728 phba->shost->host_no);
5759− phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name);
5729+ phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, wq_name);
57605730 if (!phba->wq) {
57615731 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
57625732 "BM_%d : beiscsi_dev_probe-"
@@ -5881,7 +5851,6 @@ static void beiscsi_remove(struct pci_dev *pcidev) · 118 unmodified lines
58815851
58825852 /* free all resources */
58835853 destroy_workqueue(phba->wq);
5884− beiscsi_cleanup_port(phba);
58855854 beiscsi_free_mem(phba);
58865855
58875856 /* ctrl uninit */
drivers/scsi/be2iscsi/be_main.h+10−34
@@ -36,7 +36,7 @@ · 35 unmodified lines
3636 #include <scsi/scsi_transport_iscsi.h>
3737
3838 #define DRV_NAME "be2iscsi"
39−#define BUILD_STR "11.2.0.0"
39+#define BUILD_STR "11.2.1.0"
4040 #define BE_NAME "Emulex OneConnect" \
4141 "Open-iSCSI Driver version" BUILD_STR
4242 #define DRV_DESC BE_NAME " " "Driver"
@@ -57,7 +57,6 @@ · 14 unmodified lines
5757
5858 #define BE2_IO_DEPTH 1024
5959 #define BE2_MAX_SESSIONS 256
60−#define BE2_CMDS_PER_CXN 128
6160 #define BE2_TMFS 16
6261 #define BE2_NOPOUT_REQ 16
6362 #define BE2_SGE 32
@@ -72,8 +71,13 @@ · 8 unmodified lines
7271
7372 #define BEISCSI_SGLIST_ELEMENTS 30
7473
75−#define BEISCSI_CMD_PER_LUN 128 /* scsi_host->cmd_per_lun */
76−#define BEISCSI_MAX_SECTORS 1024 /* scsi_host->max_sectors */
74+/**
75+ * BE_INVLDT_CMD_TBL_SZ is 128 which is total number commands that can
76+ * be invalidated at a time, consider it before changing the value of
77+ * BEISCSI_CMD_PER_LUN.
78+ */
79+#define BEISCSI_CMD_PER_LUN 128 /* scsi_host->cmd_per_lun */
80+#define BEISCSI_MAX_SECTORS 1024 /* scsi_host->max_sectors */
7781 #define BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE 128 /* Template size per cxn */
7882
7983 #define BEISCSI_MAX_CMD_LEN 16 /* scsi_host->max_cmd_len */
@@ -239,19 +243,7 @@ struct hba_parameters { · 159 unmodified lines
239243 unsigned int num_cq_entries;
240244 unsigned int num_eq_entries;
241245 unsigned int wrbs_per_cxn;
242− unsigned int crashmode;
243− unsigned int hba_num;
244−
245− unsigned int mgmt_ws_sz;
246246 unsigned int hwi_ws_sz;
247−
248− unsigned int eto;
249− unsigned int ldto;
250−
251− unsigned int dbg_flags;
252− unsigned int num_cxn;
253−
254− unsigned int eq_timer;
255247 /**
256248 * These are calculated from other params. They're here
257249 * for debug purposes
@@ -272,11 +264,6 @@ struct hba_parameters { · 14 unmodified lines
272264 unsigned int num_sge;
273265 };
274266
275−struct invalidate_command_table {
276− unsigned short icd;
277− unsigned short cid;
278−} __packed;
279−
280267 #define BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, cri) \
281268 (phwi_ctrlr->wrb_context[cri].ulp_num)
282269 struct hwi_wrb_context {
@@ -334,7 +321,6 @@ struct beiscsi_hba { · 51 unmodified lines
334321 struct be_bus_address pci_pa; /* CSR */
335322 /* PCI representation of our HBA */
336323 struct pci_dev *pcidev;
337− unsigned short asic_revision;
338324 unsigned int num_cpus;
339325 unsigned int nxt_cqid;
340326 struct msix_entry msix_entries[MAX_CPUS];
@@ -355,9 +341,9 @@ struct beiscsi_hba { · 14 unmodified lines
355341 spinlock_t io_sgl_lock;
356342 spinlock_t mgmt_sgl_lock;
357343 spinlock_t async_pdu_lock;
358− unsigned int age;
359344 struct list_head hba_queue;
360345 #define BE_MAX_SESSION 2048
346+#define BE_INVALID_CID 0xffff
361347 #define BE_SET_CID_TO_CRI(cri_index, cid) \
362348 (phba->cid_to_cri_map[cid] = cri_index)
363349 #define BE_GET_CRI_FROM_CID(cid) (phba->cid_to_cri_map[cid])
@@ -425,12 +411,10 @@ struct beiscsi_hba { · 61 unmodified lines
425411 u8 port_name;
426412 u8 port_speed;
427413 char fw_ver_str[BEISCSI_VER_STRLEN];
428− char wq_name[20];
429414 struct workqueue_struct *wq; /* The actuak work queue */
430415 struct be_ctrl_info ctrl;
431416 unsigned int generation;
432417 unsigned int interface_handle;
433− struct invalidate_command_table inv_tbl[128];
434418
435419 struct be_aic_obj aic_obj[MAX_CPUS];
436420 unsigned int attr_log_enable;
@@ -525,10 +509,6 @@ struct beiscsi_io_task { · 88 unmodified lines
525509 struct scsi_cmnd *scsi_cmnd;
526510 int num_sg;
527511 struct hwi_wrb_context *pwrb_context;
528− unsigned int cmd_sn;
529− unsigned int flags;
530− unsigned short cid;
531− unsigned short header_len;
532512 itt_t libiscsi_itt;
533513 struct be_cmd_bhs *cmd_bhs;
534514 struct be_bus_address bhs_pa;
@@ -842,7 +822,7 @@ struct amap_iscsi_wrb_v2 { · 307 unmodified lines
842822 u8 diff_enbl; /* DWORD 11 */
843823 u8 u_run; /* DWORD 11 */
844824 u8 o_run; /* DWORD 11 */
845− u8 invalid; /* DWORD 11 */
825+ u8 invld; /* DWORD 11 */
846826 u8 dsp; /* DWORD 11 */
847827 u8 dmsg; /* DWORD 11 */
848828 u8 rsvd4; /* DWORD 11 */
@@ -1042,10 +1022,8 @@ struct hwi_controller { · 193 unmodified lines
10421022 struct list_head io_sgl_list;
10431023 struct list_head eh_sgl_list;
10441024 struct sgl_handle *psgl_handle_base;
1045− unsigned int wrb_mem_index;
10461025
10471026 struct hwi_wrb_context *wrb_context;
1048− struct mcc_wrb *pmcc_wrb_base;
10491027 struct be_ring default_pdu_hdr[BEISCSI_ULP_COUNT];
10501028 struct be_ring default_pdu_data[BEISCSI_ULP_COUNT];
10511029 struct hwi_context_memory *phwi_ctxt;
@@ -1062,9 +1040,7 @@ enum hwh_type_enum { · 10 unmodified lines
10621040 };
10631041
10641042 struct wrb_handle {
1065− enum hwh_type_enum type;
10661043 unsigned short wrb_index;
1067−
10681044 struct iscsi_task *pio_handle;
10691045 struct iscsi_wrb *pwrb;
10701046 };
drivers/scsi/be2iscsi/be_mgmt.c+66−51
@@ -66,7 +66,6 @@ unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl, · 65 unmodified lines
6666 struct bsg_job *job,
6767 struct be_dma_mem *nonemb_cmd)
6868 {
69− struct be_cmd_resp_hdr *resp;
7069 struct be_mcc_wrb *wrb;
7170 struct be_sge *mcc_sge;
7271 unsigned int tag = 0;
@@ -76,7 +75,6 @@ unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl, · 3 unmodified lines
7675
7776 nonemb_cmd->size = job->request_payload.payload_len;
7877 memset(nonemb_cmd->va, 0, nonemb_cmd->size);
79− resp = nonemb_cmd->va;
8078 region = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
8179 sector_size = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
8280 sector = bsg_req->rqst_data.h_vendor.vendor_cmd[3];
@@ -128,50 +126,6 @@ unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl, · 45 unmodified lines
128126 return tag;
129127 }
130128
131−unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
132− struct invalidate_command_table *inv_tbl,
133− unsigned int num_invalidate, unsigned int cid,
134− struct be_dma_mem *nonemb_cmd)
135−
136−{
137− struct be_ctrl_info *ctrl = &phba->ctrl;
138− struct be_mcc_wrb *wrb;
139− struct be_sge *sge;
140− struct invalidate_commands_params_in *req;
141− unsigned int i, tag;
142−
143− mutex_lock(&ctrl->mbox_lock);
144− wrb = alloc_mcc_wrb(phba, &tag);
145− if (!wrb) {
146− mutex_unlock(&ctrl->mbox_lock);
147− return 0;
148− }
149−
150− req = nonemb_cmd->va;
151− memset(req, 0, sizeof(*req));
152− sge = nonembedded_sgl(wrb);
153−
154− be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
155− be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
156− OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
157− sizeof(*req));
158− req->ref_handle = 0;
159− req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
160− for (i = 0; i < num_invalidate; i++) {
161− req->table[i].icd = inv_tbl->icd;
162− req->table[i].cid = inv_tbl->cid;
163− req->icd_count++;
164− inv_tbl++;
165− }
166− sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
167− sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
168− sge->len = cpu_to_le32(nonemb_cmd->size);
169−
170− be_mcc_notify(phba, tag);
171− mutex_unlock(&ctrl->mbox_lock);
172− return tag;
173−}
174−
175129 unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba,
176130 struct beiscsi_endpoint *beiscsi_ep,
177131 unsigned short cid,
@@ -1066,7 +1020,6 @@ unsigned int beiscsi_boot_reopen_sess(struct beiscsi_hba *phba) · 888 unmodified lines
10661020 unsigned int beiscsi_boot_get_sinfo(struct beiscsi_hba *phba)
10671021 {
10681022 struct be_ctrl_info *ctrl = &phba->ctrl;
1069− struct be_cmd_get_session_resp *resp;
10701023 struct be_cmd_get_session_req *req;
10711024 struct be_dma_mem *nonemb_cmd;
10721025 struct be_mcc_wrb *wrb;
@@ -1081,7 +1034,7 @@ unsigned int beiscsi_boot_get_sinfo(struct beiscsi_hba *phba) · 8 unmodified lines
10811034 }
10821035
10831036 nonemb_cmd = &phba->boot_struct.nonemb_cmd;
1084− nonemb_cmd->size = sizeof(*resp);
1037+ nonemb_cmd->size = sizeof(struct be_cmd_get_session_resp);
10851038 nonemb_cmd->va = pci_alloc_consistent(phba->ctrl.pdev,
10861039 nonemb_cmd->size,
10871040 &nonemb_cmd->dma);
@@ -1096,7 +1049,7 @@ unsigned int beiscsi_boot_get_sinfo(struct beiscsi_hba *phba) · 8 unmodified lines
10961049 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
10971050 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
10981051 OPCODE_ISCSI_INI_SESSION_GET_A_SESSION,
1099− sizeof(*resp));
1052+ sizeof(struct be_cmd_get_session_resp));
11001053 req->session_handle = phba->boot_struct.s_handle;
11011054 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
11021055 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
@@ -1309,7 +1262,8 @@ beiscsi_adap_family_disp(struct device *dev, struct device_attribute *attr, · 206 unmodified lines
13091262 case BE_DEVICE_ID1:
13101263 case OC_DEVICE_ID1:
13111264 case OC_DEVICE_ID2:
1312− return snprintf(buf, PAGE_SIZE, "BE2 Adapter Family\n");
1265+ return snprintf(buf, PAGE_SIZE,
1266+ "Obsolete/Unsupported BE2 Adapter Family\n");
13131267 break;
13141268 case BE_DEVICE_ID2:
13151269 case OC_DEVICE_ID3:
@@ -1341,7 +1295,7 @@ beiscsi_phys_port_disp(struct device *dev, struct device_attribute *attr, · 25 unmodified lines
13411295 struct Scsi_Host *shost = class_to_shost(dev);
13421296 struct beiscsi_hba *phba = iscsi_host_priv(shost);
13431297
1344− return snprintf(buf, PAGE_SIZE, "Port Identifier : %d\n",
1298+ return snprintf(buf, PAGE_SIZE, "Port Identifier : %u\n",
13451299 phba->fw_config.phys_port);
13461300 }
13471301
@@ -1494,3 +1448,64 @@ void beiscsi_offload_cxn_v2(struct beiscsi_offload_params *params, · 146 unmodified lines
14941448 (params->dw[offsetof(struct amap_beiscsi_offload_params,
14951449 exp_statsn) / 32] + 1));
14961450 }
1451+
1452+int beiscsi_mgmt_invalidate_icds(struct beiscsi_hba *phba,
1453+ struct invldt_cmd_tbl *inv_tbl,
1454+ unsigned int nents)
1455+{
1456+ struct be_ctrl_info *ctrl = &phba->ctrl;
1457+ struct invldt_cmds_params_in *req;
1458+ struct be_dma_mem nonemb_cmd;
1459+ struct be_mcc_wrb *wrb;
1460+ unsigned int i, tag;
1461+ struct be_sge *sge;
1462+ int rc;
1463+
1464+ if (!nents || nents > BE_INVLDT_CMD_TBL_SZ)
1465+ return -EINVAL;
1466+
1467+ nonemb_cmd.size = sizeof(union be_invldt_cmds_params);
1468+ nonemb_cmd.va = pci_zalloc_consistent(phba->ctrl.pdev,
1469+ nonemb_cmd.size,
1470+ &nonemb_cmd.dma);
1471+ if (!nonemb_cmd.va) {
1472+ beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
1473+ "BM_%d : invldt_cmds_params alloc failed\n");
1474+ return -ENOMEM;
1475+ }
1476+
1477+ mutex_lock(&ctrl->mbox_lock);
1478+ wrb = alloc_mcc_wrb(phba, &tag);
1479+ if (!wrb) {
1480+ mutex_unlock(&ctrl->mbox_lock);
1481+ pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1482+ nonemb_cmd.va, nonemb_cmd.dma);
1483+ return -ENOMEM;
1484+ }
1485+
1486+ req = nonemb_cmd.va;
1487+ be_wrb_hdr_prepare(wrb, nonemb_cmd.size, false, 1);
1488+ be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
1489+ OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
1490+ sizeof(*req));
1491+ req->ref_handle = 0;
1492+ req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
1493+ for (i = 0; i < nents; i++) {
1494+ req->table[i].icd = inv_tbl[i].icd;
1495+ req->table[i].cid = inv_tbl[i].cid;
1496+ req->icd_count++;
1497+ }
1498+ sge = nonembedded_sgl(wrb);
1499+ sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
1500+ sge->pa_lo = cpu_to_le32(lower_32_bits(nonemb_cmd.dma));
1501+ sge->len = cpu_to_le32(nonemb_cmd.size);
1502+
1503+ be_mcc_notify(phba, tag);
1504+ mutex_unlock(&ctrl->mbox_lock);
1505+
1506+ rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd);
1507+ if (rc != -EBUSY)
1508+ pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1509+ nonemb_cmd.va, nonemb_cmd.dma);
1510+ return rc;
1511+}
drivers/scsi/be2iscsi/be_mgmt.h+17−81
@@ -36,66 +36,6 @@ · 35 unmodified lines
3636 #define PCICFG_UE_STATUS_MASK_LOW 0xA8
3737 #define PCICFG_UE_STATUS_MASK_HI 0xAC
3838
39−/**
40− * Pseudo amap definition in which each bit of the actual structure is defined
41− * as a byte: used to calculate offset/shift/mask of each field
42− */
43−struct amap_mcc_sge {
44− u8 pa_lo[32]; /* dword 0 */
45− u8 pa_hi[32]; /* dword 1 */
46− u8 length[32]; /* DWORD 2 */
47−} __packed;
48−
49−/**
50− * Pseudo amap definition in which each bit of the actual structure is defined
51− * as a byte: used to calculate offset/shift/mask of each field
52− */
53−struct amap_mcc_wrb_payload {
54− union {
55− struct amap_mcc_sge sgl[19];
56− u8 embedded[59 * 32]; /* DWORDS 57 to 115 */
57− } u;
58−} __packed;
59−
60−/**
61− * Pseudo amap definition in which each bit of the actual structure is defined
62− * as a byte: used to calculate offset/shift/mask of each field
63− */
64−struct amap_mcc_wrb {
65− u8 embedded; /* DWORD 0 */
66− u8 rsvd0[2]; /* DWORD 0 */
67− u8 sge_count[5]; /* DWORD 0 */
68− u8 rsvd1[16]; /* DWORD 0 */
69− u8 special[8]; /* DWORD 0 */
70− u8 payload_length[32];
71− u8 tag[64]; /* DWORD 2 */
72− u8 rsvd2[32]; /* DWORD 4 */
73− struct amap_mcc_wrb_payload payload;
74−};
75−
76−struct mcc_sge {
77− u32 pa_lo; /* dword 0 */
78− u32 pa_hi; /* dword 1 */
79− u32 length; /* DWORD 2 */
80−} __packed;
81−
82−struct mcc_wrb_payload {
83− union {
84− struct mcc_sge sgl[19];
85− u32 embedded[59]; /* DWORDS 57 to 115 */
86− } u;
87−} __packed;
88−
89−#define MCC_WRB_EMBEDDED_MASK 0x00000001
90−
91−struct mcc_wrb {
92− u32 dw[0]; /* DWORD 0 */
93− u32 payload_length;
94− u32 tag[2]; /* DWORD 2 */
95− u32 rsvd2[1]; /* DWORD 4 */
96− struct mcc_wrb_payload payload;
97−};
98−
9939 int mgmt_open_connection(struct beiscsi_hba *phba,
10040 struct sockaddr *dst_addr,
10141 struct beiscsi_endpoint *beiscsi_ep,
@@ -104,10 +44,6 @@ int mgmt_open_connection(struct beiscsi_hba *phba, · 2 unmodified lines
10444 unsigned int mgmt_upload_connection(struct beiscsi_hba *phba,
10545 unsigned short cid,
10646 unsigned int upload_flag);
107−unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
108− struct invalidate_command_table *inv_tbl,
109− unsigned int num_invalidate, unsigned int cid,
110− struct be_dma_mem *nonemb_cmd);
11147 unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl,
11248 struct beiscsi_hba *phba,
11349 struct bsg_job *job,
@@ -134,24 +70,31 @@ union iscsi_invalidate_connection_params { · 20 unmodified lines
13470 struct iscsi_invalidate_connection_params_out response;
13571 } __packed;
13672
137−struct invalidate_commands_params_in {
73+#define BE_INVLDT_CMD_TBL_SZ 128
74+struct invldt_cmd_tbl {
75+ unsigned short icd;
76+ unsigned short cid;
77+} __packed;
78+
79+struct invldt_cmds_params_in {
13880 struct be_cmd_req_hdr hdr;
13981 unsigned int ref_handle;
14082 unsigned int icd_count;
141− struct invalidate_command_table table[128];
83+ struct invldt_cmd_tbl table[BE_INVLDT_CMD_TBL_SZ];
14284 unsigned short cleanup_type;
14385 unsigned short unused;
14486 } __packed;
14587
146−struct invalidate_commands_params_out {
88+struct invldt_cmds_params_out {
89+ struct be_cmd_resp_hdr hdr;
14790 unsigned int ref_handle;
14891 unsigned int icd_count;
149− unsigned int icd_status[128];
92+ unsigned int icd_status[BE_INVLDT_CMD_TBL_SZ];
15093 } __packed;
15194
152−union invalidate_commands_params {
153− struct invalidate_commands_params_in request;
154− struct invalidate_commands_params_out response;
95+union be_invldt_cmds_params {
96+ struct invldt_cmds_params_in request;
97+ struct invldt_cmds_params_out response;
15598 } __packed;
15699
157100 struct mgmt_hba_attributes {
@@ -231,16 +174,6 @@ struct be_bsg_vendor_cmd { · 73 unmodified lines
231174
232175 #define GET_MGMT_CONTROLLER_WS(phba) (phba->pmgmt_ws)
233176
234−/* MGMT CMD flags */
235−
236−#define MGMT_CMDH_FREE (1<<0)
237−
238−/* --- MGMT_ERROR_CODES --- */
239−/* Error Codes returned in the status field of the CMD response header */
240−#define MGMT_STATUS_SUCCESS 0 /* The CMD completed without errors */
241−#define MGMT_STATUS_FAILED 1 /* Error status in the Status field of */
242− /* the CMD_RESPONSE_HEADER */
243−
244177 #define ISCSI_GET_PDU_TEMPLATE_ADDRESS(pc, pa) {\
245178 pa->lo = phba->init_mem[ISCSI_MEM_GLOBAL_HEADER].mem_array[0].\
246179 bus_address.u.a32.address_lo; \
@@ -270,6 +203,9 @@ unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba, · 23 unmodified lines
270203 unsigned short cid,
271204 unsigned short issue_reset,
272205 unsigned short savecfg_flag);
206+int beiscsi_mgmt_invalidate_icds(struct beiscsi_hba *phba,
207+ struct invldt_cmd_tbl *inv_tbl,
208+ unsigned int nents);
273209
274210 int beiscsi_if_en_dhcp(struct beiscsi_hba *phba, u32 ip_type);
275211
drivers/scsi/bfa/bfa_fcs.c+46−135
@@ -27,24 +27,6 @@ · 26 unmodified lines
2727
2828 BFA_TRC_FILE(FCS, FCS);
2929
30−/*
31− * FCS sub-modules
32− */
33−struct bfa_fcs_mod_s {
34− void (*attach) (struct bfa_fcs_s *fcs);
35− void (*modinit) (struct bfa_fcs_s *fcs);
36− void (*modexit) (struct bfa_fcs_s *fcs);
37−};
38−
39−#define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
40−
41−static struct bfa_fcs_mod_s fcs_modules[] = {
42− { bfa_fcs_port_attach, NULL, NULL },
43− { bfa_fcs_uf_attach, NULL, NULL },
44− { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
45− bfa_fcs_fabric_modexit },
46−};
47−
4830 /*
4931 * fcs_api BFA FCS API
5032 */
@@ -58,52 +40,19 @@ bfa_fcs_exit_comp(void *fcs_cbarg) · 7 unmodified lines
5840 complete(&bfad->comp);
5941 }
6042
61−
62−
6343 /*
64− * fcs_api BFA FCS API
65− */
66−
67−/*
68− * fcs attach -- called once to initialize data structures at driver attach time
44+ * fcs initialization, called once after bfa initialization is complete
6945 */
7046 void
71−bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
72− bfa_boolean_t min_cfg)
47+bfa_fcs_init(struct bfa_fcs_s *fcs)
7348 {
74− int i;
75− struct bfa_fcs_mod_s *mod;
76−
77− fcs->bfa = bfa;
78− fcs->bfad = bfad;
79− fcs->min_cfg = min_cfg;
80− fcs->num_rport_logins = 0;
81−
82− bfa->fcs = BFA_TRUE;
83− fcbuild_init();
84−
85− for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) {
86− mod = &fcs_modules[i];
87− if (mod->attach)
88− mod->attach(fcs);
89− }
49+ bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
50+ bfa_trc(fcs, 0);
9051 }
9152
9253 /*
93− * fcs initialization, called once after bfa initialization is complete
54+ * fcs_api BFA FCS API
9455 */
95−void
96−bfa_fcs_init(struct bfa_fcs_s *fcs)
97−{
98− int i;
99− struct bfa_fcs_mod_s *mod;
100−
101− for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) {
102− mod = &fcs_modules[i];
103− if (mod->modinit)
104− mod->modinit(fcs);
105− }
106−}
10756
10857 /*
10958 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
@@ -180,26 +129,14 @@ bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs, · 70 unmodified lines
180129 void
181130 bfa_fcs_exit(struct bfa_fcs_s *fcs)
182131 {
183− struct bfa_fcs_mod_s *mod;
184− int nmods, i;
185−
186132 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
187−
188− nmods = ARRAY_SIZE(fcs_modules);
189−
190− for (i = 0; i < nmods; i++) {
191−
192− mod = &fcs_modules[i];
193− if (mod->modexit) {
194− bfa_wc_up(&fcs->wc);
195− mod->modexit(fcs);
196− }
197− }
198−
133+ bfa_wc_up(&fcs->wc);
134+ bfa_trc(fcs, 0);
135+ bfa_lps_delete(fcs->fabric.lps);
136+ bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_DELETE);
199137 bfa_wc_wait(&fcs->wc);
200138 }
201139
202−
203140 /*
204141 * Fabric module implementation.
205142 */
@@ -1127,62 +1064,6 @@ bfa_fcs_fabric_stop_comp(void *cbarg) · 921 unmodified lines
11271064 * fcs_fabric_public fabric public functions
11281065 */
11291066
1130−/*
1131− * Attach time initialization.
1132− */
1133−void
1134−bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
1135−{
1136− struct bfa_fcs_fabric_s *fabric;
1137−
1138− fabric = &fcs->fabric;
1139− memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
1140−
1141− /*
1142− * Initialize base fabric.
1143− */
1144− fabric->fcs = fcs;
1145− INIT_LIST_HEAD(&fabric->vport_q);
1146− INIT_LIST_HEAD(&fabric->vf_q);
1147− fabric->lps = bfa_lps_alloc(fcs->bfa);
1148− WARN_ON(!fabric->lps);
1149−
1150− /*
1151− * Initialize fabric delete completion handler. Fabric deletion is
1152− * complete when the last vport delete is complete.
1153− */
1154− bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1155− bfa_wc_up(&fabric->wc); /* For the base port */
1156−
1157− bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1158− bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
1159−}
1160−
1161−void
1162−bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1163−{
1164− bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
1165− bfa_trc(fcs, 0);
1166−}
1167−
1168−/*
1169− * Module cleanup
1170− */
1171−void
1172−bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1173−{
1174− struct bfa_fcs_fabric_s *fabric;
1175−
1176− bfa_trc(fcs, 0);
1177−
1178− /*
1179− * Cleanup base fabric.
1180− */
1181− fabric = &fcs->fabric;
1182− bfa_lps_delete(fabric->lps);
1183− bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1184−}
1185−
11861067 /*
11871068 * Fabric module stop -- stop FCS actions
11881069 */
@@ -1633,12 +1514,6 @@ bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event) · 444 unmodified lines
16331514 }
16341515 }
16351516
1636−void
1637−bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1638−{
1639− bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1640−}
1641−
16421517 /*
16431518 * BFA FCS UF ( Unsolicited Frames)
16441519 */
@@ -1706,8 +1581,44 @@ bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf) · 61 unmodified lines
17061581 bfa_uf_free(uf);
17071582 }
17081583
1584+/*
1585+ * fcs attach -- called once to initialize data structures at driver attach time
1586+ */
17091587 void
1710−bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1588+bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
1589+ bfa_boolean_t min_cfg)
17111590 {
1591+ struct bfa_fcs_fabric_s *fabric = &fcs->fabric;
1592+
1593+ fcs->bfa = bfa;
1594+ fcs->bfad = bfad;
1595+ fcs->min_cfg = min_cfg;
1596+ fcs->num_rport_logins = 0;
1597+
1598+ bfa->fcs = BFA_TRUE;
1599+ fcbuild_init();
1600+
1601+ bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
17121602 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
1603+
1604+ memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
1605+
1606+ /*
1607+ * Initialize base fabric.
1608+ */
1609+ fabric->fcs = fcs;
1610+ INIT_LIST_HEAD(&fabric->vport_q);
1611+ INIT_LIST_HEAD(&fabric->vf_q);
1612+ fabric->lps = bfa_lps_alloc(fcs->bfa);
1613+ WARN_ON(!fabric->lps);
1614+
1615+ /*
1616+ * Initialize fabric delete completion handler. Fabric deletion is
1617+ * complete when the last vport delete is complete.
1618+ */
1619+ bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1620+ bfa_wc_up(&fabric->wc); /* For the base port */
1621+
1622+ bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1623+ bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
17131624 }
drivers/scsi/bfa/bfa_fcs.h+0−4
@@ -808,9 +808,7 @@ void bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t vpwwn[], int *nports); · 807 unmodified lines
808808 /*
809809 * fabric protected interface functions
810810 */
811−void bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs);
812811 void bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs);
813−void bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs);
814812 void bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric);
815813 void bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric);
816814 void bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
@@ -827,8 +825,6 @@ void bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric); · 10 unmodified lines
827825 void bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
828826 wwn_t fabric_name);
829827 u16 bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric);
830−void bfa_fcs_uf_attach(struct bfa_fcs_s *fcs);
831−void bfa_fcs_port_attach(struct bfa_fcs_s *fcs);
832828 void bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs);
833829 void bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
834830 enum bfa_fcs_fabric_event event);
drivers/scsi/bfa/bfad_im.c+2−0
@@ -813,6 +813,7 @@ struct scsi_host_template bfad_im_scsi_host_template = { · 812 unmodified lines
813813 .name = BFAD_DRIVER_NAME,
814814 .info = bfad_im_info,
815815 .queuecommand = bfad_im_queuecommand,
816+ .eh_timed_out = fc_eh_timed_out,
816817 .eh_abort_handler = bfad_im_abort_handler,
817818 .eh_device_reset_handler = bfad_im_reset_lun_handler,
818819 .eh_bus_reset_handler = bfad_im_reset_bus_handler,
@@ -835,6 +836,7 @@ struct scsi_host_template bfad_im_vport_template = { · 16 unmodified lines
835836 .name = BFAD_DRIVER_NAME,
836837 .info = bfad_im_info,
837838 .queuecommand = bfad_im_queuecommand,
839+ .eh_timed_out = fc_eh_timed_out,
838840 .eh_abort_handler = bfad_im_abort_handler,
839841 .eh_device_reset_handler = bfad_im_reset_lun_handler,
840842 .eh_bus_reset_handler = bfad_im_reset_bus_handler,
drivers/scsi/bnx2fc/bnx2fc_fcoe.c+1−0
@@ -2947,6 +2947,7 @@ static struct scsi_host_template bnx2fc_shost_template = { · 2946 unmodified lines
29472947 .module = THIS_MODULE,
29482948 .name = "QLogic Offload FCoE Initiator",
29492949 .queuecommand = bnx2fc_queuecommand,
2950+ .eh_timed_out = fc_eh_timed_out,
29502951 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
29512952 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
29522953 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
drivers/scsi/bnx2i/bnx2i_iscsi.c+1−0
@@ -2259,6 +2259,7 @@ static struct scsi_host_template bnx2i_host_template = { · 2258 unmodified lines
22592259 .name = "QLogic Offload iSCSI Initiator",
22602260 .proc_name = "bnx2i",
22612261 .queuecommand = iscsi_queuecommand,
2262+ .eh_timed_out = iscsi_eh_cmd_timed_out,
22622263 .eh_abort_handler = iscsi_eh_abort,
22632264 .eh_device_reset_handler = iscsi_eh_device_reset,
22642265 .eh_target_reset_handler = iscsi_eh_recover_target,
drivers/scsi/csiostor/csio_scsi.c+2−0
@@ -2270,6 +2270,7 @@ struct scsi_host_template csio_fcoe_shost_template = { · 2269 unmodified lines
22702270 .name = CSIO_DRV_DESC,
22712271 .proc_name = KBUILD_MODNAME,
22722272 .queuecommand = csio_queuecommand,
2273+ .eh_timed_out = fc_eh_timed_out,
22732274 .eh_abort_handler = csio_eh_abort_handler,
22742275 .eh_device_reset_handler = csio_eh_lun_reset_handler,
22752276 .slave_alloc = csio_slave_alloc,
@@ -2289,6 +2290,7 @@ struct scsi_host_template csio_fcoe_shost_vport_template = { · 13 unmodified lines
22892290 .name = CSIO_DRV_DESC,
22902291 .proc_name = KBUILD_MODNAME,
22912292 .queuecommand = csio_queuecommand,
2293+ .eh_timed_out = fc_eh_timed_out,
22922294 .eh_abort_handler = csio_eh_abort_handler,
22932295 .eh_device_reset_handler = csio_eh_lun_reset_handler,
22942296 .slave_alloc = csio_slave_alloc,
drivers/scsi/cxgbi/cxgb3i/cxgb3i.c+1−0
@@ -90,6 +90,7 @@ static struct scsi_host_template cxgb3i_host_template = { · 89 unmodified lines
9090 .sg_tablesize = SG_ALL,
9191 .max_sectors = 0xFFFF,
9292 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
93+ .eh_timed_out = iscsi_eh_cmd_timed_out,
9394 .eh_abort_handler = iscsi_eh_abort,
9495 .eh_device_reset_handler = iscsi_eh_device_reset,
9596 .eh_target_reset_handler = iscsi_eh_recover_target,
drivers/scsi/cxgbi/cxgb4i/cxgb4i.c+1−0
@@ -103,6 +103,7 @@ static struct scsi_host_template cxgb4i_host_template = { · 102 unmodified lines
103103 .sg_tablesize = SG_ALL,
104104 .max_sectors = 0xFFFF,
105105 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
106+ .eh_timed_out = iscsi_eh_cmd_timed_out,
106107 .eh_abort_handler = iscsi_eh_abort,
107108 .eh_device_reset_handler = iscsi_eh_device_reset,
108109 .eh_target_reset_handler = iscsi_eh_recover_target,
drivers/scsi/cxlflash/common.h+28−4
@@ -54,6 +54,9 @@ extern const struct file_operations cxlflash_cxl_fops; · 53 unmodified lines
5454 /* RRQ for master issued cmds */
5555 #define NUM_RRQ_ENTRY CXLFLASH_MAX_CMDS
5656
57+/* SQ for master issued cmds */
58+#define NUM_SQ_ENTRY CXLFLASH_MAX_CMDS
59+
5760
5861 static inline void check_sizes(void)
5962 {
@@ -155,8 +158,8 @@ static inline struct afu_cmd *sc_to_afucz(struct scsi_cmnd *sc) · 95 unmodified lines
155158
156159 struct afu {
157160 /* Stuff requiring alignment go first. */
158−
159− u64 rrq_entry[NUM_RRQ_ENTRY]; /* 2K RRQ */
161+ struct sisl_ioarcb sq[NUM_SQ_ENTRY]; /* 16K SQ */
162+ u64 rrq_entry[NUM_RRQ_ENTRY]; /* 2K RRQ */
160163
161164 /* Beware of alignment till here. Preferably introduce new
162165 * fields after this point
@@ -171,9 +174,13 @@ struct afu { · 8 unmodified lines
171174 struct sisl_host_map __iomem *host_map; /* MC host map */
172175 struct sisl_ctrl_map __iomem *ctrl_map; /* MC control map */
173176
174− struct kref mapcount;
175−
176177 ctx_hndl_t ctx_hndl; /* master's context handle */
178+
179+ atomic_t hsq_credits;
180+ spinlock_t hsq_slock;
181+ struct sisl_ioarcb *hsq_start;
182+ struct sisl_ioarcb *hsq_end;
183+ struct sisl_ioarcb *hsq_curr;
177184 u64 *hrrq_start;
178185 u64 *hrrq_end;
179186 u64 *hrrq_curr;
@@ -191,6 +198,23 @@ struct afu { · 11 unmodified lines
191198
192199 };
193200
201+static inline bool afu_is_cmd_mode(struct afu *afu, u64 cmd_mode)
202+{
203+ u64 afu_cap = afu->interface_version >> SISL_INTVER_CAP_SHIFT;
204+
205+ return afu_cap & cmd_mode;
206+}
207+
208+static inline bool afu_is_sq_cmd_mode(struct afu *afu)
209+{
210+ return afu_is_cmd_mode(afu, SISL_INTVER_CAP_SQ_CMD_MODE);
211+}
212+
213+static inline bool afu_is_ioarrin_cmd_mode(struct afu *afu)
214+{
215+ return afu_is_cmd_mode(afu, SISL_INTVER_CAP_IOARRIN_CMD_MODE);
216+}
217+
194218 static inline u64 lun_to_lunid(u64 lun)
195219 {
196220 __be64 lun_id;
drivers/scsi/cxlflash/lunmgt.c+18−13
@@ -32,11 +32,13 @@ · 31 unmodified lines
3232 */
3333 static struct llun_info *create_local(struct scsi_device *sdev, u8 *wwid)
3434 {
35+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
36+ struct device *dev = &cfg->dev->dev;
3537 struct llun_info *lli = NULL;
3638
3739 lli = kzalloc(sizeof(*lli), GFP_KERNEL);
3840 if (unlikely(!lli)) {
39− pr_err("%s: could not allocate lli\n", __func__);
41+ dev_err(dev, "%s: could not allocate lli\n", __func__);
4042 goto out;
4143 }
4244
@@ -58,11 +60,13 @@ out: · 15 unmodified lines
5860 */
5961 static struct glun_info *create_global(struct scsi_device *sdev, u8 *wwid)
6062 {
63+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
64+ struct device *dev = &cfg->dev->dev;
6165 struct glun_info *gli = NULL;
6266
6367 gli = kzalloc(sizeof(*gli), GFP_KERNEL);
6468 if (unlikely(!gli)) {
65− pr_err("%s: could not allocate gli\n", __func__);
69+ dev_err(dev, "%s: could not allocate gli\n", __func__);
6670 goto out;
6771 }
6872
@@ -129,10 +133,10 @@ static struct glun_info *lookup_global(u8 *wwid) · 60 unmodified lines
129133 */
130134 static struct llun_info *find_and_create_lun(struct scsi_device *sdev, u8 *wwid)
131135 {
136+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
137+ struct device *dev = &cfg->dev->dev;
132138 struct llun_info *lli = NULL;
133139 struct glun_info *gli = NULL;
134− struct Scsi_Host *shost = sdev->host;
135− struct cxlflash_cfg *cfg = shost_priv(shost);
136140
137141 if (unlikely(!wwid))
138142 goto out;
@@ -165,7 +169,7 @@ static struct llun_info *find_and_create_lun(struct scsi_device *sdev, u8 *wwid) · 26 unmodified lines
165169 list_add(&gli->list, &global.gluns);
166170
167171 out:
168− pr_debug("%s: returning %p\n", __func__, lli);
172+ dev_dbg(dev, "%s: returning lli=%p, gli=%p\n", __func__, lli, gli);
169173 return lli;
170174 }
171175
@@ -225,17 +229,18 @@ void cxlflash_term_global_luns(void) · 53 unmodified lines
225229 int cxlflash_manage_lun(struct scsi_device *sdev,
226230 struct dk_cxlflash_manage_lun *manage)
227231 {
228− int rc = 0;
232+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
233+ struct device *dev = &cfg->dev->dev;
229234 struct llun_info *lli = NULL;
235+ int rc = 0;
230236 u64 flags = manage->hdr.flags;
231237 u32 chan = sdev->channel;
232238
233239 mutex_lock(&global.mutex);
234240 lli = find_and_create_lun(sdev, manage->wwid);
235− pr_debug("%s: ENTER: WWID = %016llX%016llX, flags = %016llX li = %p\n",
236− __func__, get_unaligned_be64(&manage->wwid[0]),
237− get_unaligned_be64(&manage->wwid[8]),
238− manage->hdr.flags, lli);
241+ dev_dbg(dev, "%s: WWID=%016llx%016llx, flags=%016llx lli=%p\n",
242+ __func__, get_unaligned_be64(&manage->wwid[0]),
243+ get_unaligned_be64(&manage->wwid[8]), manage->hdr.flags, lli);
239244 if (unlikely(!lli)) {
240245 rc = -ENOMEM;
241246 goto out;
@@ -265,11 +270,11 @@ int cxlflash_manage_lun(struct scsi_device *sdev, · 23 unmodified lines
265270 }
266271 }
267272
268− pr_debug("%s: port_sel = %08X chan = %u lun_id = %016llX\n", __func__,
269− lli->port_sel, chan, lli->lun_id[chan]);
273+ dev_dbg(dev, "%s: port_sel=%08x chan=%u lun_id=%016llx\n",
274+ __func__, lli->port_sel, chan, lli->lun_id[chan]);
270275
271276 out:
272277 mutex_unlock(&global.mutex);
273− pr_debug("%s: returning rc=%d\n", __func__, rc);
278+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
274279 return rc;
275280 }
drivers/scsi/cxlflash/main.c+264−201
@@ -43,6 +43,9 @@ MODULE_LICENSE("GPL"); · 42 unmodified lines
4343 */
4444 static void process_cmd_err(struct afu_cmd *cmd, struct scsi_cmnd *scp)
4545 {
46+ struct afu *afu = cmd->parent;
47+ struct cxlflash_cfg *cfg = afu->parent;
48+ struct device *dev = &cfg->dev->dev;
4649 struct sisl_ioarcb *ioarcb;
4750 struct sisl_ioasa *ioasa;
4851 u32 resid;
@@ -56,21 +59,20 @@ static void process_cmd_err(struct afu_cmd *cmd, struct scsi_cmnd *scp) · 7 unmodified lines
5659 if (ioasa->rc.flags & SISL_RC_FLAGS_UNDERRUN) {
5760 resid = ioasa->resid;
5861 scsi_set_resid(scp, resid);
59− pr_debug("%s: cmd underrun cmd = %p scp = %p, resid = %d\n",
60− __func__, cmd, scp, resid);
62+ dev_dbg(dev, "%s: cmd underrun cmd = %p scp = %p, resid = %d\n",
63+ __func__, cmd, scp, resid);
6164 }
6265
6366 if (ioasa->rc.flags & SISL_RC_FLAGS_OVERRUN) {
64− pr_debug("%s: cmd underrun cmd = %p scp = %p\n",
65− __func__, cmd, scp);
67+ dev_dbg(dev, "%s: cmd underrun cmd = %p scp = %p\n",
68+ __func__, cmd, scp);
6669 scp->result = (DID_ERROR << 16);
6770 }
6871
69− pr_debug("%s: cmd failed afu_rc=%d scsi_rc=%d fc_rc=%d "
70− "afu_extra=0x%X, scsi_extra=0x%X, fc_extra=0x%X\n",
71− __func__, ioasa->rc.afu_rc, ioasa->rc.scsi_rc,
72− ioasa->rc.fc_rc, ioasa->afu_extra, ioasa->scsi_extra,
73− ioasa->fc_extra);
72+ dev_dbg(dev, "%s: cmd failed afu_rc=%02x scsi_rc=%02x fc_rc=%02x "
73+ "afu_extra=%02x scsi_extra=%02x fc_extra=%02x\n", __func__,
74+ ioasa->rc.afu_rc, ioasa->rc.scsi_rc, ioasa->rc.fc_rc,
75+ ioasa->afu_extra, ioasa->scsi_extra, ioasa->fc_extra);
7476
7577 if (ioasa->rc.scsi_rc) {
7678 /* We have a SCSI status */
@@ -159,6 +161,7 @@ static void cmd_complete(struct afu_cmd *cmd) · 82 unmodified lines
159161 ulong lock_flags;
160162 struct afu *afu = cmd->parent;
161163 struct cxlflash_cfg *cfg = afu->parent;
164+ struct device *dev = &cfg->dev->dev;
162165 bool cmd_is_tmf;
163166
164167 if (cmd->scp) {
@@ -170,9 +173,8 @@ static void cmd_complete(struct afu_cmd *cmd) · 5 unmodified lines
170173
171174 cmd_is_tmf = cmd->cmd_tmf;
172175
173− pr_debug_ratelimited("%s: calling scsi_done scp=%p result=%X "
174− "ioasc=%d\n", __func__, scp, scp->result,
175− cmd->sa.ioasc);
176+ dev_dbg_ratelimited(dev, "%s:scp=%p result=%08x ioasc=%08x\n",
177+ __func__, scp, scp->result, cmd->sa.ioasc);
176178
177179 scsi_dma_unmap(scp);
178180 scp->scsi_done(scp);
@@ -188,10 +190,11 @@ static void cmd_complete(struct afu_cmd *cmd) · 9 unmodified lines
188190 }
189191
190192 /**
191− * context_reset_ioarrin() - reset command owner context via IOARRIN register
193+ * context_reset() - reset command owner context via specified register
192194 * @cmd: AFU command that timed out.
195+ * @reset_reg: MMIO register to perform reset.
193196 */
194−static void context_reset_ioarrin(struct afu_cmd *cmd)
197+static void context_reset(struct afu_cmd *cmd, __be64 __iomem *reset_reg)
195198 {
196199 int nretry = 0;
197200 u64 rrin = 0x1;
@@ -199,21 +202,43 @@ static void context_reset_ioarrin(struct afu_cmd *cmd) · 1 unmodified line
199202 struct cxlflash_cfg *cfg = afu->parent;
200203 struct device *dev = &cfg->dev->dev;
201204
202− pr_debug("%s: cmd=%p\n", __func__, cmd);
205+ dev_dbg(dev, "%s: cmd=%p\n", __func__, cmd);
203206
204− writeq_be(rrin, &afu->host_map->ioarrin);
207+ writeq_be(rrin, reset_reg);
205208 do {
206− rrin = readq_be(&afu->host_map->ioarrin);
209+ rrin = readq_be(reset_reg);
207210 if (rrin != 0x1)
208211 break;
209212 /* Double delay each time */
210213 udelay(1 << nretry);
211214 } while (nretry++ < MC_ROOM_RETRY_CNT);
212215
213− dev_dbg(dev, "%s: returning rrin=0x%016llX nretry=%d\n",
216+ dev_dbg(dev, "%s: returning rrin=%016llx nretry=%d\n",
214217 __func__, rrin, nretry);
215218 }
216219
220+/**
221+ * context_reset_ioarrin() - reset command owner context via IOARRIN register
222+ * @cmd: AFU command that timed out.
223+ */
224+static void context_reset_ioarrin(struct afu_cmd *cmd)
225+{
226+ struct afu *afu = cmd->parent;
227+
228+ context_reset(cmd, &afu->host_map->ioarrin);
229+}
230+
231+/**
232+ * context_reset_sq() - reset command owner context w/ SQ Context Reset register
233+ * @cmd: AFU command that timed out.
234+ */
235+static void context_reset_sq(struct afu_cmd *cmd)
236+{
237+ struct afu *afu = cmd->parent;
238+
239+ context_reset(cmd, &afu->host_map->sq_ctx_reset);
240+}
241+
217242 /**
218243 * send_cmd_ioarrin() - sends an AFU command via IOARRIN register
219244 * @afu: AFU associated with the host.
@@ -251,8 +276,51 @@ static int send_cmd_ioarrin(struct afu *afu, struct afu_cmd *cmd) · 31 unmodified lines
251276 writeq_be((u64)&cmd->rcb, &afu->host_map->ioarrin);
252277 out:
253278 spin_unlock_irqrestore(&afu->rrin_slock, lock_flags);
254− pr_devel("%s: cmd=%p len=%d ea=%p rc=%d\n", __func__, cmd,
255− cmd->rcb.data_len, (void *)cmd->rcb.data_ea, rc);
279+ dev_dbg(dev, "%s: cmd=%p len=%u ea=%016llx rc=%d\n", __func__,
280+ cmd, cmd->rcb.data_len, cmd->rcb.data_ea, rc);
281+ return rc;
282+}
283+
284+/**
285+ * send_cmd_sq() - sends an AFU command via SQ ring
286+ * @afu: AFU associated with the host.
287+ * @cmd: AFU command to send.
288+ *
289+ * Return:
290+ * 0 on success, SCSI_MLQUEUE_HOST_BUSY on failure
291+ */
292+static int send_cmd_sq(struct afu *afu, struct afu_cmd *cmd)
293+{
294+ struct cxlflash_cfg *cfg = afu->parent;
295+ struct device *dev = &cfg->dev->dev;
296+ int rc = 0;
297+ int newval;
298+ ulong lock_flags;
299+
300+ newval = atomic_dec_if_positive(&afu->hsq_credits);
301+ if (newval <= 0) {
302+ rc = SCSI_MLQUEUE_HOST_BUSY;
303+ goto out;
304+ }
305+
306+ cmd->rcb.ioasa = &cmd->sa;
307+
308+ spin_lock_irqsave(&afu->hsq_slock, lock_flags);
309+
310+ *afu->hsq_curr = cmd->rcb;
311+ if (afu->hsq_curr < afu->hsq_end)
312+ afu->hsq_curr++;
313+ else
314+ afu->hsq_curr = afu->hsq_start;
315+ writeq_be((u64)afu->hsq_curr, &afu->host_map->sq_tail);
316+
317+ spin_unlock_irqrestore(&afu->hsq_slock, lock_flags);
318+out:
319+ dev_dbg(dev, "%s: cmd=%p len=%u ea=%016llx ioasa=%p rc=%d curr=%p "
320+ "head=%016llx tail=%016llx\n", __func__, cmd, cmd->rcb.data_len,
321+ cmd->rcb.data_ea, cmd->rcb.ioasa, rc, afu->hsq_curr,
322+ readq_be(&afu->host_map->sq_head),
323+ readq_be(&afu->host_map->sq_tail));
256324 return rc;
257325 }
258326
@@ -266,6 +334,8 @@ out: · 7 unmodified lines
266334 */
267335 static int wait_resp(struct afu *afu, struct afu_cmd *cmd)
268336 {
337+ struct cxlflash_cfg *cfg = afu->parent;
338+ struct device *dev = &cfg->dev->dev;
269339 int rc = 0;
270340 ulong timeout = msecs_to_jiffies(cmd->rcb.timeout * 2 * 1000);
271341
@@ -276,10 +346,8 @@ static int wait_resp(struct afu *afu, struct afu_cmd *cmd) · 4 unmodified lines
276346 }
277347
278348 if (unlikely(cmd->sa.ioasc != 0)) {
279− pr_err("%s: CMD 0x%X failed, IOASC: flags 0x%X, afu_rc 0x%X, "
280− "scsi_rc 0x%X, fc_rc 0x%X\n", __func__, cmd->rcb.cdb[0],
281− cmd->sa.rc.flags, cmd->sa.rc.afu_rc, cmd->sa.rc.scsi_rc,
282− cmd->sa.rc.fc_rc);
349+ dev_err(dev, "%s: cmd %02x failed, ioasc=%08x\n",
350+ __func__, cmd->rcb.cdb[0], cmd->sa.ioasc);
283351 rc = -1;
284352 }
285353
@@ -298,8 +366,7 @@ static int wait_resp(struct afu *afu, struct afu_cmd *cmd) · 12 unmodified lines
298366 static int send_tmf(struct afu *afu, struct scsi_cmnd *scp, u64 tmfcmd)
299367 {
300368 u32 port_sel = scp->device->channel + 1;
301− struct Scsi_Host *host = scp->device->host;
302− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata;
369+ struct cxlflash_cfg *cfg = shost_priv(scp->device->host);
303370 struct afu_cmd *cmd = sc_to_afucz(scp);
304371 struct device *dev = &cfg->dev->dev;
305372 ulong lock_flags;
@@ -344,7 +411,7 @@ static int send_tmf(struct afu *afu, struct scsi_cmnd *scp, u64 tmfcmd) · 38 unmodified lines
344411 to);
345412 if (!to) {
346413 cfg->tmf_active = false;
347− dev_err(dev, "%s: TMF timed out!\n", __func__);
414+ dev_err(dev, "%s: TMF timed out\n", __func__);
348415 rc = -1;
349416 }
350417 spin_unlock_irqrestore(&cfg->tmf_slock, lock_flags);
@@ -352,16 +419,6 @@ out: · 1 unmodified line
352419 return rc;
353420 }
354421
355−static void afu_unmap(struct kref *ref)
356−{
357− struct afu *afu = container_of(ref, struct afu, mapcount);
358−
359− if (likely(afu->afu_map)) {
360− cxl_psa_unmap((void __iomem *)afu->afu_map);
361− afu->afu_map = NULL;
362− }
363−}
364−
365422 /**
366423 * cxlflash_driver_info() - information handler for this host driver
367424 * @host: SCSI host associated with device.
@@ -382,7 +439,7 @@ static const char *cxlflash_driver_info(struct Scsi_Host *host) · 14 unmodified lines
382439 */
383440 static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp)
384441 {
385− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata;
442+ struct cxlflash_cfg *cfg = shost_priv(host);
386443 struct afu *afu = cfg->afu;
387444 struct device *dev = &cfg->dev->dev;
388445 struct afu_cmd *cmd = sc_to_afucz(scp);
@@ -392,10 +449,9 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp) · 3 unmodified lines
392449 ulong lock_flags;
393450 int nseg = 0;
394451 int rc = 0;
395− int kref_got = 0;
396452
397453 dev_dbg_ratelimited(dev, "%s: (scp=%p) %d/%d/%d/%llu "
398− "cdb=(%08X-%08X-%08X-%08X)\n",
454+ "cdb=(%08x-%08x-%08x-%08x)\n",
399455 __func__, scp, host->host_no, scp->device->channel,
400456 scp->device->id, scp->device->lun,
401457 get_unaligned_be32(&((u32 *)scp->cmnd)[0]),
@@ -417,11 +473,11 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp) · 15 unmodified lines
417473
418474 switch (cfg->state) {
419475 case STATE_RESET:
420− dev_dbg_ratelimited(dev, "%s: device is in reset!\n", __func__);
476+ dev_dbg_ratelimited(dev, "%s: device is in reset\n", __func__);
421477 rc = SCSI_MLQUEUE_HOST_BUSY;
422478 goto out;
423479 case STATE_FAILTERM:
424− dev_dbg_ratelimited(dev, "%s: device has failed!\n", __func__);
480+ dev_dbg_ratelimited(dev, "%s: device has failed\n", __func__);
425481 scp->result = (DID_NO_CONNECT << 16);
426482 scp->scsi_done(scp);
427483 rc = 0;
@@ -430,13 +486,10 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp) · 2 unmodified lines
430486 break;
431487 }
432488
433− kref_get(&cfg->afu->mapcount);
434− kref_got = 1;
435−
436489 if (likely(sg)) {
437490 nseg = scsi_dma_map(scp);
438491 if (unlikely(nseg < 0)) {
439− dev_err(dev, "%s: Fail DMA map!\n", __func__);
492+ dev_err(dev, "%s: Fail DMA map\n", __func__);
440493 rc = SCSI_MLQUEUE_HOST_BUSY;
441494 goto out;
442495 }
@@ -463,9 +516,6 @@ static int cxlflash_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scp) · 20 unmodified lines
463516 if (unlikely(rc))
464517 scsi_dma_unmap(scp);
465518 out:
466− if (kref_got)
467− kref_put(&afu->mapcount, afu_unmap);
468− pr_devel("%s: returning rc=%d\n", __func__, rc);
469519 return rc;
470520 }
471521
@@ -503,13 +553,15 @@ static void free_mem(struct cxlflash_cfg *cfg) · 31 unmodified lines
503553 *
504554 * Safe to call with AFU in a partially allocated/initialized state.
505555 *
506− * Waits for any active internal AFU commands to timeout and then unmaps
507− * the MMIO space.
556+ * Cancels scheduled worker threads, waits for any active internal AFU
557+ * commands to timeout and then unmaps the MMIO space.
508558 */
509559 static void stop_afu(struct cxlflash_cfg *cfg)
510560 {
511561 struct afu *afu = cfg->afu;
512562
563+ cancel_work_sync(&cfg->work_q);
564+
513565 if (likely(afu)) {
514566 while (atomic_read(&afu->cmds_active))
515567 ssleep(1);
@@ -517,7 +569,6 @@ static void stop_afu(struct cxlflash_cfg *cfg) · 1 unmodified line
517569 cxl_psa_unmap((void __iomem *)afu->afu_map);
518570 afu->afu_map = NULL;
519571 }
520− kref_put(&afu->mapcount, afu_unmap);
521572 }
522573 }
523574
@@ -585,6 +636,8 @@ static void term_mc(struct cxlflash_cfg *cfg) · 61 unmodified lines
585636 */
586637 static void term_afu(struct cxlflash_cfg *cfg)
587638 {
639+ struct device *dev = &cfg->dev->dev;
640+
588641 /*
589642 * Tear down is carefully orchestrated to ensure
590643 * no interrupts can come in when the problem state
@@ -600,7 +653,7 @@ static void term_afu(struct cxlflash_cfg *cfg) · 9 unmodified lines
600653
601654 term_mc(cfg);
602655
603− pr_debug("%s: returning\n", __func__);
656+ dev_dbg(dev, "%s: returning\n", __func__);
604657 }
605658
606659 /**
@@ -627,8 +680,7 @@ static void notify_shutdown(struct cxlflash_cfg *cfg, bool wait) · 20 unmodified lines
627680 return;
628681
629682 if (!afu || !afu->afu_map) {
630− dev_dbg(dev, "%s: The problem state area is not mapped\n",
631− __func__);
683+ dev_dbg(dev, "%s: Problem state area not mapped\n", __func__);
632684 return;
633685 }
634686
@@ -670,10 +722,11 @@ static void notify_shutdown(struct cxlflash_cfg *cfg, bool wait) · 35 unmodified lines
670722 static void cxlflash_remove(struct pci_dev *pdev)
671723 {
672724 struct cxlflash_cfg *cfg = pci_get_drvdata(pdev);
725+ struct device *dev = &pdev->dev;
673726 ulong lock_flags;
674727
675728 if (!pci_is_enabled(pdev)) {
676− pr_debug("%s: Device is disabled\n", __func__);
729+ dev_dbg(dev, "%s: Device is disabled\n", __func__);
677730 return;
678731 }
679732
@@ -699,7 +752,6 @@ static void cxlflash_remove(struct pci_dev *pdev) · 19 unmodified lines
699752 scsi_remove_host(cfg->host);
700753 /* fall through */
701754 case INIT_STATE_AFU:
702− cancel_work_sync(&cfg->work_q);
703755 term_afu(cfg);
704756 case INIT_STATE_PCI:
705757 pci_disable_device(pdev);
@@ -709,7 +761,7 @@ static void cxlflash_remove(struct pci_dev *pdev) · 3 unmodified lines
709761 break;
710762 }
711763
712− pr_debug("%s: returning\n", __func__);
764+ dev_dbg(dev, "%s: returning\n", __func__);
713765 }
714766
715767 /**
@@ -727,7 +779,7 @@ static int alloc_mem(struct cxlflash_cfg *cfg) · 11 unmodified lines
727779 int rc = 0;
728780 struct device *dev = &cfg->dev->dev;
729781
730− /* AFU is ~12k, i.e. only one 64k page or up to four 4k pages */
782+ /* AFU is ~28k, i.e. only one 64k page or up to seven 4k pages */
731783 cfg->afu = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
732784 get_order(sizeof(struct afu)));
733785 if (unlikely(!cfg->afu)) {
@@ -751,6 +803,7 @@ out: · 17 unmodified lines
751803 static int init_pci(struct cxlflash_cfg *cfg)
752804 {
753805 struct pci_dev *pdev = cfg->dev;
806+ struct device *dev = &cfg->dev->dev;
754807 int rc = 0;
755808
756809 rc = pci_enable_device(pdev);
@@ -761,15 +814,14 @@ static int init_pci(struct cxlflash_cfg *cfg) · 4 unmodified lines
761814 }
762815
763816 if (rc) {
764− dev_err(&pdev->dev, "%s: Cannot enable adapter\n",
765− __func__);
817+ dev_err(dev, "%s: Cannot enable adapter\n", __func__);
766818 cxlflash_wait_for_pci_err_recovery(cfg);
767819 goto out;
768820 }
769821 }
770822
771823 out:
772− pr_debug("%s: returning rc=%d\n", __func__, rc);
824+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
773825 return rc;
774826 }
775827
@@ -782,19 +834,19 @@ out: · 6 unmodified lines
782834 static int init_scsi(struct cxlflash_cfg *cfg)
783835 {
784836 struct pci_dev *pdev = cfg->dev;
837+ struct device *dev = &cfg->dev->dev;
785838 int rc = 0;
786839
787840 rc = scsi_add_host(cfg->host, &pdev->dev);
788841 if (rc) {
789− dev_err(&pdev->dev, "%s: scsi_add_host failed (rc=%d)\n",
790− __func__, rc);
842+ dev_err(dev, "%s: scsi_add_host failed rc=%d\n", __func__, rc);
791843 goto out;
792844 }
793845
794846 scsi_scan_host(cfg->host);
795847
796848 out:
797− pr_debug("%s: returning rc=%d\n", __func__, rc);
849+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
798850 return rc;
799851 }
800852
@@ -844,16 +896,12 @@ static void set_port_offline(__be64 __iomem *fc_regs) · 43 unmodified lines
844896 * Return:
845897 * TRUE (1) when the specified port is online
846898 * FALSE (0) when the specified port fails to come online after timeout
847− * -EINVAL when @delay_us is less than 1000
848899 */
849−static int wait_port_online(__be64 __iomem *fc_regs, u32 delay_us, u32 nretry)
900+static bool wait_port_online(__be64 __iomem *fc_regs, u32 delay_us, u32 nretry)
850901 {
851902 u64 status;
852903
853− if (delay_us < 1000) {
854− pr_err("%s: invalid delay specified %d\n", __func__, delay_us);
855− return -EINVAL;
856− }
904+ WARN_ON(delay_us < 1000);
857905
858906 do {
859907 msleep(delay_us / 1000);
@@ -877,16 +925,12 @@ static int wait_port_online(__be64 __iomem *fc_regs, u32 delay_us, u32 nretry) · 17 unmodified lines
877925 * Return:
878926 * TRUE (1) when the specified port is offline
879927 * FALSE (0) when the specified port fails to go offline after timeout
880− * -EINVAL when @delay_us is less than 1000
881928 */
882−static int wait_port_offline(__be64 __iomem *fc_regs, u32 delay_us, u32 nretry)
929+static bool wait_port_offline(__be64 __iomem *fc_regs, u32 delay_us, u32 nretry)
883930 {
884931 u64 status;
885932
886− if (delay_us < 1000) {
887− pr_err("%s: invalid delay specified %d\n", __func__, delay_us);
888− return -EINVAL;
889− }
933+ WARN_ON(delay_us < 1000);
890934
891935 do {
892936 msleep(delay_us / 1000);
@@ -915,11 +959,14 @@ static int wait_port_offline(__be64 __iomem *fc_regs, u32 delay_us, u32 nretry) · 22 unmodified lines
915959 static void afu_set_wwpn(struct afu *afu, int port, __be64 __iomem *fc_regs,
916960 u64 wwpn)
917961 {
962+ struct cxlflash_cfg *cfg = afu->parent;
963+ struct device *dev = &cfg->dev->dev;
964+
918965 set_port_offline(fc_regs);
919966 if (!wait_port_offline(fc_regs, FC_PORT_STATUS_RETRY_INTERVAL_US,
920967 FC_PORT_STATUS_RETRY_CNT)) {
921− pr_debug("%s: wait on port %d to go offline timed out\n",
922− __func__, port);
968+ dev_dbg(dev, "%s: wait on port %d to go offline timed out\n",
969+ __func__, port);
923970 }
924971
925972 writeq_be(wwpn, &fc_regs[FC_PNAME / 8]);
@@ -927,8 +974,8 @@ static void afu_set_wwpn(struct afu *afu, int port, __be64 __iomem *fc_regs, · 1 unmodified line
927974 set_port_online(fc_regs);
928975 if (!wait_port_online(fc_regs, FC_PORT_STATUS_RETRY_INTERVAL_US,
929976 FC_PORT_STATUS_RETRY_CNT)) {
930− pr_debug("%s: wait on port %d to go online timed out\n",
931− __func__, port);
977+ dev_dbg(dev, "%s: wait on port %d to go online timed out\n",
978+ __func__, port);
932979 }
933980 }
934981
@@ -947,6 +994,8 @@ static void afu_set_wwpn(struct afu *afu, int port, __be64 __iomem *fc_regs, · 12 unmodified lines
947994 */
948995 static void afu_link_reset(struct afu *afu, int port, __be64 __iomem *fc_regs)
949996 {
997+ struct cxlflash_cfg *cfg = afu->parent;
998+ struct device *dev = &cfg->dev->dev;
950999 u64 port_sel;
9511000
9521001 /* first switch the AFU to the other links, if any */
@@ -958,21 +1007,21 @@ static void afu_link_reset(struct afu *afu, int port, __be64 __iomem *fc_regs) · 5 unmodified lines
9581007 set_port_offline(fc_regs);
9591008 if (!wait_port_offline(fc_regs, FC_PORT_STATUS_RETRY_INTERVAL_US,
9601009 FC_PORT_STATUS_RETRY_CNT))
961− pr_err("%s: wait on port %d to go offline timed out\n",
962− __func__, port);
1010+ dev_err(dev, "%s: wait on port %d to go offline timed out\n",
1011+ __func__, port);
9631012
9641013 set_port_online(fc_regs);
9651014 if (!wait_port_online(fc_regs, FC_PORT_STATUS_RETRY_INTERVAL_US,
9661015 FC_PORT_STATUS_RETRY_CNT))
967− pr_err("%s: wait on port %d to go online timed out\n",
968− __func__, port);
1016+ dev_err(dev, "%s: wait on port %d to go online timed out\n",
1017+ __func__, port);
9691018
9701019 /* switch back to include this port */
9711020 port_sel |= (1ULL << port);
9721021 writeq_be(port_sel, &afu->afu_map->global.regs.afu_port_sel);
9731022 cxlflash_afu_sync(afu, 0, 0, AFU_GSYNC);
9741023
975− pr_debug("%s: returning port_sel=%lld\n", __func__, port_sel);
1024+ dev_dbg(dev, "%s: returning port_sel=%016llx\n", __func__, port_sel);
9761025 }
9771026
9781027 /*
@@ -1082,6 +1131,8 @@ static void afu_err_intr_init(struct afu *afu) · 103 unmodified lines
10821131 static irqreturn_t cxlflash_sync_err_irq(int irq, void *data)
10831132 {
10841133 struct afu *afu = (struct afu *)data;
1134+ struct cxlflash_cfg *cfg = afu->parent;
1135+ struct device *dev = &cfg->dev->dev;
10851136 u64 reg;
10861137 u64 reg_unmasked;
10871138
@@ -1089,18 +1140,17 @@ static irqreturn_t cxlflash_sync_err_irq(int irq, void *data) · 1 unmodified line
10891140 reg_unmasked = (reg & SISL_ISTATUS_UNMASK);
10901141
10911142 if (reg_unmasked == 0UL) {
1092− pr_err("%s: %llX: spurious interrupt, intr_status %016llX\n",
1093− __func__, (u64)afu, reg);
1143+ dev_err(dev, "%s: spurious interrupt, intr_status=%016llx\n",
1144+ __func__, reg);
10941145 goto cxlflash_sync_err_irq_exit;
10951146 }
10961147
1097− pr_err("%s: %llX: unexpected interrupt, intr_status %016llX\n",
1098− __func__, (u64)afu, reg);
1148+ dev_err(dev, "%s: unexpected interrupt, intr_status=%016llx\n",
1149+ __func__, reg);
10991150
11001151 writeq_be(reg_unmasked, &afu->host_map->intr_clear);
11011152
11021153 cxlflash_sync_err_irq_exit:
1103− pr_debug("%s: returning rc=%d\n", __func__, IRQ_HANDLED);
11041154 return IRQ_HANDLED;
11051155 }
11061156
@@ -1115,6 +1165,8 @@ static irqreturn_t cxlflash_rrq_irq(int irq, void *data) · 8 unmodified lines
11151165 {
11161166 struct afu *afu = (struct afu *)data;
11171167 struct afu_cmd *cmd;
1168+ struct sisl_ioasa *ioasa;
1169+ struct sisl_ioarcb *ioarcb;
11181170 bool toggle = afu->toggle;
11191171 u64 entry,
11201172 *hrrq_start = afu->hrrq_start,
@@ -1128,7 +1180,16 @@ static irqreturn_t cxlflash_rrq_irq(int irq, void *data) · 7 unmodified lines
11281180 if ((entry & SISL_RESP_HANDLE_T_BIT) != toggle)
11291181 break;
11301182
1131− cmd = (struct afu_cmd *)(entry & ~SISL_RESP_HANDLE_T_BIT);
1183+ entry &= ~SISL_RESP_HANDLE_T_BIT;
1184+
1185+ if (afu_is_sq_cmd_mode(afu)) {
1186+ ioasa = (struct sisl_ioasa *)entry;
1187+ cmd = container_of(ioasa, struct afu_cmd, sa);
1188+ } else {
1189+ ioarcb = (struct sisl_ioarcb *)entry;
1190+ cmd = container_of(ioarcb, struct afu_cmd, rcb);
1191+ }
1192+
11321193 cmd_complete(cmd);
11331194
11341195 /* Advance to next entry or wrap and flip the toggle bit */
@@ -1138,6 +1199,8 @@ static irqreturn_t cxlflash_rrq_irq(int irq, void *data) · 3 unmodified lines
11381199 hrrq_curr = hrrq_start;
11391200 toggle ^= SISL_RESP_HANDLE_T_BIT;
11401201 }
1202+
1203+ atomic_inc(&afu->hsq_credits);
11411204 }
11421205
11431206 afu->hrrq_curr = hrrq_curr;
@@ -1169,7 +1232,7 @@ static irqreturn_t cxlflash_async_err_irq(int irq, void *data) · 25 unmodified lines
11691232 reg_unmasked = (reg & SISL_ASTATUS_UNMASK);
11701233
11711234 if (reg_unmasked == 0) {
1172− dev_err(dev, "%s: spurious interrupt, aintr_status 0x%016llX\n",
1235+ dev_err(dev, "%s: spurious interrupt, aintr_status=%016llx\n",
11731236 __func__, reg);
11741237 goto out;
11751238 }
@@ -1185,7 +1248,7 @@ static irqreturn_t cxlflash_async_err_irq(int irq, void *data) · 9 unmodified lines
11851248
11861249 port = info->port;
11871250
1188− dev_err(dev, "%s: FC Port %d -> %s, fc_status 0x%08llX\n",
1251+ dev_err(dev, "%s: FC Port %d -> %s, fc_status=%016llx\n",
11891252 __func__, port, info->desc,
11901253 readq_be(&global->fc_regs[port][FC_STATUS / 8]));
11911254
@@ -1198,7 +1261,6 @@ static irqreturn_t cxlflash_async_err_irq(int irq, void *data) · 6 unmodified lines
11981261 __func__, port);
11991262 cfg->lr_state = LINK_RESET_REQUIRED;
12001263 cfg->lr_port = port;
1201− kref_get(&cfg->afu->mapcount);
12021264 schedule_work(&cfg->work_q);
12031265 }
12041266
@@ -1210,7 +1272,7 @@ static irqreturn_t cxlflash_async_err_irq(int irq, void *data) · 5 unmodified lines
12101272 * should be the same and tracing one is sufficient.
12111273 */
12121274
1213− dev_err(dev, "%s: fc %d: clearing fc_error 0x%08llX\n",
1275+ dev_err(dev, "%s: fc %d: clearing fc_error=%016llx\n",
12141276 __func__, port, reg);
12151277
12161278 writeq_be(reg, &global->fc_regs[port][FC_ERROR / 8]);
@@ -1219,13 +1281,11 @@ static irqreturn_t cxlflash_async_err_irq(int irq, void *data) · 2 unmodified lines
12191281
12201282 if (info->action & SCAN_HOST) {
12211283 atomic_inc(&cfg->scan_host_needed);
1222− kref_get(&cfg->afu->mapcount);
12231284 schedule_work(&cfg->work_q);
12241285 }
12251286 }
12261287
12271288 out:
1228− dev_dbg(dev, "%s: returning IRQ_HANDLED, afu=%p\n", __func__, afu);
12291289 return IRQ_HANDLED;
12301290 }
12311291
@@ -1237,13 +1297,14 @@ out: · 5 unmodified lines
12371297 */
12381298 static int start_context(struct cxlflash_cfg *cfg)
12391299 {
1300+ struct device *dev = &cfg->dev->dev;
12401301 int rc = 0;
12411302
12421303 rc = cxl_start_context(cfg->mcctx,
12431304 cfg->afu->work.work_element_descriptor,
12441305 NULL);
12451306
1246− pr_debug("%s: returning rc=%d\n", __func__, rc);
1307+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
12471308 return rc;
12481309 }
12491310
@@ -1256,7 +1317,8 @@ static int start_context(struct cxlflash_cfg *cfg) · 6 unmodified lines
12561317 */
12571318 static int read_vpd(struct cxlflash_cfg *cfg, u64 wwpn[])
12581319 {
1259− struct pci_dev *dev = cfg->dev;
1320+ struct device *dev = &cfg->dev->dev;
1321+ struct pci_dev *pdev = cfg->dev;
12601322 int rc = 0;
12611323 int ro_start, ro_size, i, j, k;
12621324 ssize_t vpd_size;
@@ -1265,10 +1327,10 @@ static int read_vpd(struct cxlflash_cfg *cfg, u64 wwpn[]) · 2 unmodified lines
12651327 char *wwpn_vpd_tags[NUM_FC_PORTS] = { "V5", "V6" };
12661328
12671329 /* Get the VPD data from the device */
1268− vpd_size = cxl_read_adapter_vpd(dev, vpd_data, sizeof(vpd_data));
1330+ vpd_size = cxl_read_adapter_vpd(pdev, vpd_data, sizeof(vpd_data));
12691331 if (unlikely(vpd_size <= 0)) {
1270− dev_err(&dev->dev, "%s: Unable to read VPD (size = %ld)\n",
1271− __func__, vpd_size);
1332+ dev_err(dev, "%s: Unable to read VPD (size = %ld)\n",
1333+ __func__, vpd_size);
12721334 rc = -ENODEV;
12731335 goto out;
12741336 }
@@ -1277,8 +1339,7 @@ static int read_vpd(struct cxlflash_cfg *cfg, u64 wwpn[]) · 2 unmodified lines
12771339 ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size,
12781340 PCI_VPD_LRDT_RO_DATA);
12791341 if (unlikely(ro_start < 0)) {
1280− dev_err(&dev->dev, "%s: VPD Read-only data not found\n",
1281− __func__);
1342+ dev_err(dev, "%s: VPD Read-only data not found\n", __func__);
12821343 rc = -ENODEV;
12831344 goto out;
12841345 }
@@ -1288,8 +1349,8 @@ static int read_vpd(struct cxlflash_cfg *cfg, u64 wwpn[]) · 3 unmodified lines
12881349 j = ro_size;
12891350 i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
12901351 if (unlikely((i + j) > vpd_size)) {
1291− pr_debug("%s: Might need to read more VPD (%d > %ld)\n",
1292− __func__, (i + j), vpd_size);
1352+ dev_dbg(dev, "%s: Might need to read more VPD (%d > %ld)\n",
1353+ __func__, (i + j), vpd_size);
12931354 ro_size = vpd_size - i;
12941355 }
12951356
@@ -1307,8 +1368,8 @@ static int read_vpd(struct cxlflash_cfg *cfg, u64 wwpn[]) · 11 unmodified lines
13071368
13081369 i = pci_vpd_find_info_keyword(vpd_data, i, j, wwpn_vpd_tags[k]);
13091370 if (unlikely(i < 0)) {
1310− dev_err(&dev->dev, "%s: Port %d WWPN not found "
1311− "in VPD\n", __func__, k);
1371+ dev_err(dev, "%s: Port %d WWPN not found in VPD\n",
1372+ __func__, k);
13121373 rc = -ENODEV;
13131374 goto out;
13141375 }
@@ -1316,9 +1377,8 @@ static int read_vpd(struct cxlflash_cfg *cfg, u64 wwpn[]) · 1 unmodified line
13161377 j = pci_vpd_info_field_size(&vpd_data[i]);
13171378 i += PCI_VPD_INFO_FLD_HDR_SIZE;
13181379 if (unlikely((i + j > vpd_size) || (j != WWPN_LEN))) {
1319− dev_err(&dev->dev, "%s: Port %d WWPN incomplete or "
1320− "VPD corrupt\n",
1321− __func__, k);
1380+ dev_err(dev, "%s: Port %d WWPN incomplete or bad VPD\n",
1381+ __func__, k);
13221382 rc = -ENODEV;
13231383 goto out;
13241384 }
@@ -1326,15 +1386,15 @@ static int read_vpd(struct cxlflash_cfg *cfg, u64 wwpn[]) · 1 unmodified line
13261386 memcpy(tmp_buf, &vpd_data[i], WWPN_LEN);
13271387 rc = kstrtoul(tmp_buf, WWPN_LEN, (ulong *)&wwpn[k]);
13281388 if (unlikely(rc)) {
1329− dev_err(&dev->dev, "%s: Fail to convert port %d WWPN "
1330− "to integer\n", __func__, k);
1389+ dev_err(dev, "%s: WWPN conversion failed for port %d\n",
1390+ __func__, k);
13311391 rc = -ENODEV;
13321392 goto out;
13331393 }
13341394 }
13351395
13361396 out:
1337− pr_debug("%s: returning rc=%d\n", __func__, rc);
1397+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
13381398 return rc;
13391399 }
13401400
@@ -1388,12 +1448,18 @@ static int init_global(struct cxlflash_cfg *cfg) · 47 unmodified lines
13881448 goto out;
13891449 }
13901450
1391− pr_debug("%s: wwpn0=0x%llX wwpn1=0x%llX\n", __func__, wwpn[0], wwpn[1]);
1451+ dev_dbg(dev, "%s: wwpn0=%016llx wwpn1=%016llx\n",
1452+ __func__, wwpn[0], wwpn[1]);
13921453
1393− /* Set up RRQ in AFU for master issued cmds */
1454+ /* Set up RRQ and SQ in AFU for master issued cmds */
13941455 writeq_be((u64) afu->hrrq_start, &afu->host_map->rrq_start);
13951456 writeq_be((u64) afu->hrrq_end, &afu->host_map->rrq_end);
13961457
1458+ if (afu_is_sq_cmd_mode(afu)) {
1459+ writeq_be((u64)afu->hsq_start, &afu->host_map->sq_start);
1460+ writeq_be((u64)afu->hsq_end, &afu->host_map->sq_end);
1461+ }
1462+
13971463 /* AFU configuration */
13981464 reg = readq_be(&afu->afu_map->global.regs.afu_config);
13991465 reg |= SISL_AFUCONF_AR_ALL|SISL_AFUCONF_ENDIAN;
@@ -1443,7 +1509,6 @@ static int init_global(struct cxlflash_cfg *cfg) · 43 unmodified lines
14431509 &afu->ctrl_map->ctx_cap);
14441510 /* Initialize heartbeat */
14451511 afu->hb = readq_be(&afu->afu_map->global.regs.afu_hb);
1446−
14471512 out:
14481513 return rc;
14491514 }
@@ -1455,6 +1520,7 @@ out: · 5 unmodified lines
14551520 static int start_afu(struct cxlflash_cfg *cfg)
14561521 {
14571522 struct afu *afu = cfg->afu;
1523+ struct device *dev = &cfg->dev->dev;
14581524 int rc = 0;
14591525
14601526 init_pcr(cfg);
@@ -1468,9 +1534,20 @@ static int start_afu(struct cxlflash_cfg *cfg) · 7 unmodified lines
14681534 afu->hrrq_curr = afu->hrrq_start;
14691535 afu->toggle = 1;
14701536
1537+ /* Initialize SQ */
1538+ if (afu_is_sq_cmd_mode(afu)) {
1539+ memset(&afu->sq, 0, sizeof(afu->sq));
1540+ afu->hsq_start = &afu->sq[0];
1541+ afu->hsq_end = &afu->sq[NUM_SQ_ENTRY - 1];
1542+ afu->hsq_curr = afu->hsq_start;
1543+
1544+ spin_lock_init(&afu->hsq_slock);
1545+ atomic_set(&afu->hsq_credits, NUM_SQ_ENTRY - 1);
1546+ }
1547+
14711548 rc = init_global(cfg);
14721549
1473− pr_debug("%s: returning rc=%d\n", __func__, rc);
1550+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
14741551 return rc;
14751552 }
14761553
@@ -1490,7 +1567,7 @@ static enum undo_level init_intr(struct cxlflash_cfg *cfg, · 13 unmodified lines
14901567
14911568 rc = cxl_allocate_afu_irqs(ctx, 3);
14921569 if (unlikely(rc)) {
1493− dev_err(dev, "%s: call to allocate_afu_irqs failed rc=%d!\n",
1570+ dev_err(dev, "%s: allocate_afu_irqs failed rc=%d\n",
14941571 __func__, rc);
14951572 level = UNDO_NOOP;
14961573 goto out;
@@ -1499,8 +1576,7 @@ static enum undo_level init_intr(struct cxlflash_cfg *cfg, · 2 unmodified lines
14991576 rc = cxl_map_afu_irq(ctx, 1, cxlflash_sync_err_irq, afu,
15001577 "SISL_MSI_SYNC_ERROR");
15011578 if (unlikely(rc <= 0)) {
1502− dev_err(dev, "%s: IRQ 1 (SISL_MSI_SYNC_ERROR) map failed!\n",
1503− __func__);
1579+ dev_err(dev, "%s: SISL_MSI_SYNC_ERROR map failed\n", __func__);
15041580 level = FREE_IRQ;
15051581 goto out;
15061582 }
@@ -1508,8 +1584,7 @@ static enum undo_level init_intr(struct cxlflash_cfg *cfg, · 1 unmodified line
15081584 rc = cxl_map_afu_irq(ctx, 2, cxlflash_rrq_irq, afu,
15091585 "SISL_MSI_RRQ_UPDATED");
15101586 if (unlikely(rc <= 0)) {
1511− dev_err(dev, "%s: IRQ 2 (SISL_MSI_RRQ_UPDATED) map failed!\n",
1512− __func__);
1587+ dev_err(dev, "%s: SISL_MSI_RRQ_UPDATED map failed\n", __func__);
15131588 level = UNMAP_ONE;
15141589 goto out;
15151590 }
@@ -1517,8 +1592,7 @@ static enum undo_level init_intr(struct cxlflash_cfg *cfg, · 1 unmodified line
15171592 rc = cxl_map_afu_irq(ctx, 3, cxlflash_async_err_irq, afu,
15181593 "SISL_MSI_ASYNC_ERROR");
15191594 if (unlikely(rc <= 0)) {
1520− dev_err(dev, "%s: IRQ 3 (SISL_MSI_ASYNC_ERROR) map failed!\n",
1521− __func__);
1595+ dev_err(dev, "%s: SISL_MSI_ASYNC_ERROR map failed\n", __func__);
15221596 level = UNMAP_TWO;
15231597 goto out;
15241598 }
@@ -1552,15 +1626,13 @@ static int init_mc(struct cxlflash_cfg *cfg) · 27 unmodified lines
15521626 /* During initialization reset the AFU to start from a clean slate */
15531627 rc = cxl_afu_reset(cfg->mcctx);
15541628 if (unlikely(rc)) {
1555− dev_err(dev, "%s: initial AFU reset failed rc=%d\n",
1556− __func__, rc);
1629+ dev_err(dev, "%s: AFU reset failed rc=%d\n", __func__, rc);
15571630 goto ret;
15581631 }
15591632
15601633 level = init_intr(cfg, ctx);
15611634 if (unlikely(level)) {
1562− dev_err(dev, "%s: setting up interrupts failed rc=%d\n",
1563− __func__, rc);
1635+ dev_err(dev, "%s: interrupt init failed rc=%d\n", __func__, rc);
15641636 goto out;
15651637 }
15661638
@@ -1575,7 +1647,7 @@ static int init_mc(struct cxlflash_cfg *cfg) · 8 unmodified lines
15751647 goto out;
15761648 }
15771649 ret:
1578− pr_debug("%s: returning rc=%d\n", __func__, rc);
1650+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
15791651 return rc;
15801652 out:
15811653 term_intr(cfg, level);
@@ -1602,7 +1674,7 @@ static int init_afu(struct cxlflash_cfg *cfg) · 20 unmodified lines
16021674
16031675 rc = init_mc(cfg);
16041676 if (rc) {
1605− dev_err(dev, "%s: call to init_mc failed, rc=%d!\n",
1677+ dev_err(dev, "%s: init_mc failed rc=%d\n",
16061678 __func__, rc);
16071679 goto out;
16081680 }
@@ -1610,11 +1682,10 @@ static int init_afu(struct cxlflash_cfg *cfg) · 1 unmodified line
16101682 /* Map the entire MMIO space of the AFU */
16111683 afu->afu_map = cxl_psa_map(cfg->mcctx);
16121684 if (!afu->afu_map) {
1613− dev_err(dev, "%s: call to cxl_psa_map failed!\n", __func__);
1685+ dev_err(dev, "%s: cxl_psa_map failed\n", __func__);
16141686 rc = -ENOMEM;
16151687 goto err1;
16161688 }
1617− kref_init(&afu->mapcount);
16181689
16191690 /* No byte reverse on reading afu_version or string will be backwards */
16201691 reg = readq(&afu->afu_map->global.regs.afu_version);
@@ -1622,24 +1693,28 @@ static int init_afu(struct cxlflash_cfg *cfg) · 1 unmodified line
16221693 afu->interface_version =
16231694 readq_be(&afu->afu_map->global.regs.interface_version);
16241695 if ((afu->interface_version + 1) == 0) {
1625− pr_err("Back level AFU, please upgrade. AFU version %s "
1626− "interface version 0x%llx\n", afu->version,
1696+ dev_err(dev, "Back level AFU, please upgrade. AFU version %s "
1697+ "interface version %016llx\n", afu->version,
16271698 afu->interface_version);
16281699 rc = -EINVAL;
1629− goto err2;
1700+ goto err1;
16301701 }
16311702
1632− afu->send_cmd = send_cmd_ioarrin;
1633− afu->context_reset = context_reset_ioarrin;
1703+ if (afu_is_sq_cmd_mode(afu)) {
1704+ afu->send_cmd = send_cmd_sq;
1705+ afu->context_reset = context_reset_sq;
1706+ } else {
1707+ afu->send_cmd = send_cmd_ioarrin;
1708+ afu->context_reset = context_reset_ioarrin;
1709+ }
16341710
1635− pr_debug("%s: afu version %s, interface version 0x%llX\n", __func__,
1636− afu->version, afu->interface_version);
1711+ dev_dbg(dev, "%s: afu_ver=%s interface_ver=%016llx\n", __func__,
1712+ afu->version, afu->interface_version);
16371713
16381714 rc = start_afu(cfg);
16391715 if (rc) {
1640− dev_err(dev, "%s: call to start_afu failed, rc=%d!\n",
1641− __func__, rc);
1642− goto err2;
1716+ dev_err(dev, "%s: start_afu failed, rc=%d\n", __func__, rc);
1717+ goto err1;
16431718 }
16441719
16451720 afu_err_intr_init(cfg->afu);
@@ -1649,11 +1724,9 @@ static int init_afu(struct cxlflash_cfg *cfg) · 3 unmodified lines
16491724 /* Restore the LUN mappings */
16501725 cxlflash_restore_luntable(cfg);
16511726 out:
1652− pr_debug("%s: returning rc=%d\n", __func__, rc);
1727+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
16531728 return rc;
16541729
1655−err2:
1656− kref_put(&afu->mapcount, afu_unmap);
16571730 err1:
16581731 term_intr(cfg, UNMAP_THREE);
16591732 term_mc(cfg);
@@ -1693,7 +1766,8 @@ int cxlflash_afu_sync(struct afu *afu, ctx_hndl_t ctx_hndl_u, · 33 unmodified lines
16931766 static DEFINE_MUTEX(sync_active);
16941767
16951768 if (cfg->state != STATE_NORMAL) {
1696− pr_debug("%s: Sync not required! (%u)\n", __func__, cfg->state);
1769+ dev_dbg(dev, "%s: Sync not required state=%u\n",
1770+ __func__, cfg->state);
16971771 return 0;
16981772 }
16991773
@@ -1710,7 +1784,7 @@ int cxlflash_afu_sync(struct afu *afu, ctx_hndl_t ctx_hndl_u, · 10 unmodified lines
17101784 init_completion(&cmd->cevent);
17111785 cmd->parent = afu;
17121786
1713− pr_debug("%s: afu=%p cmd=%p %d\n", __func__, afu, cmd, ctx_hndl_u);
1787+ dev_dbg(dev, "%s: afu=%p cmd=%p %d\n", __func__, afu, cmd, ctx_hndl_u);
17141788
17151789 cmd->rcb.req_flags = SISL_REQ_FLAGS_AFU_CMD;
17161790 cmd->rcb.ctx_id = afu->ctx_hndl;
@@ -1735,7 +1809,7 @@ out: · 18 unmodified lines
17351809 atomic_dec(&afu->cmds_active);
17361810 mutex_unlock(&sync_active);
17371811 kfree(buf);
1738− pr_debug("%s: returning rc=%d\n", __func__, rc);
1812+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
17391813 return rc;
17401814 }
17411815
@@ -1747,16 +1821,17 @@ out: · 5 unmodified lines
17471821 */
17481822 static int afu_reset(struct cxlflash_cfg *cfg)
17491823 {
1824+ struct device *dev = &cfg->dev->dev;
17501825 int rc = 0;
1826+
17511827 /* Stop the context before the reset. Since the context is
17521828 * no longer available restart it after the reset is complete
17531829 */
1754−
17551830 term_afu(cfg);
17561831
17571832 rc = init_afu(cfg);
17581833
1759− pr_debug("%s: returning rc=%d\n", __func__, rc);
1834+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
17601835 return rc;
17611836 }
17621837
@@ -1785,18 +1860,18 @@ static int cxlflash_eh_device_reset_handler(struct scsi_cmnd *scp) · 22 unmodified lines
17851860 {
17861861 int rc = SUCCESS;
17871862 struct Scsi_Host *host = scp->device->host;
1788− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata;
1863+ struct cxlflash_cfg *cfg = shost_priv(host);
1864+ struct device *dev = &cfg->dev->dev;
17891865 struct afu *afu = cfg->afu;
17901866 int rcr = 0;
17911867
1792− pr_debug("%s: (scp=%p) %d/%d/%d/%llu "
1793− "cdb=(%08X-%08X-%08X-%08X)\n", __func__, scp,
1794− host->host_no, scp->device->channel,
1795− scp->device->id, scp->device->lun,
1796− get_unaligned_be32(&((u32 *)scp->cmnd)[0]),
1797− get_unaligned_be32(&((u32 *)scp->cmnd)[1]),
1798− get_unaligned_be32(&((u32 *)scp->cmnd)[2]),
1799− get_unaligned_be32(&((u32 *)scp->cmnd)[3]));
1868+ dev_dbg(dev, "%s: (scp=%p) %d/%d/%d/%llu "
1869+ "cdb=(%08x-%08x-%08x-%08x)\n", __func__, scp, host->host_no,
1870+ scp->device->channel, scp->device->id, scp->device->lun,
1871+ get_unaligned_be32(&((u32 *)scp->cmnd)[0]),
1872+ get_unaligned_be32(&((u32 *)scp->cmnd)[1]),
1873+ get_unaligned_be32(&((u32 *)scp->cmnd)[2]),
1874+ get_unaligned_be32(&((u32 *)scp->cmnd)[3]));
18001875
18011876 retry:
18021877 switch (cfg->state) {
@@ -1813,7 +1888,7 @@ retry: · 10 unmodified lines
18131888 break;
18141889 }
18151890
1816− pr_debug("%s: returning rc=%d\n", __func__, rc);
1891+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
18171892 return rc;
18181893 }
18191894
@@ -1835,16 +1910,16 @@ static int cxlflash_eh_host_reset_handler(struct scsi_cmnd *scp) · 15 unmodified lines
18351910 int rc = SUCCESS;
18361911 int rcr = 0;
18371912 struct Scsi_Host *host = scp->device->host;
1838− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)host->hostdata;
1913+ struct cxlflash_cfg *cfg = shost_priv(host);
1914+ struct device *dev = &cfg->dev->dev;
18391915
1840− pr_debug("%s: (scp=%p) %d/%d/%d/%llu "
1841− "cdb=(%08X-%08X-%08X-%08X)\n", __func__, scp,
1842− host->host_no, scp->device->channel,
1843− scp->device->id, scp->device->lun,
1844− get_unaligned_be32(&((u32 *)scp->cmnd)[0]),
1845− get_unaligned_be32(&((u32 *)scp->cmnd)[1]),
1846− get_unaligned_be32(&((u32 *)scp->cmnd)[2]),
1847− get_unaligned_be32(&((u32 *)scp->cmnd)[3]));
1916+ dev_dbg(dev, "%s: (scp=%p) %d/%d/%d/%llu "
1917+ "cdb=(%08x-%08x-%08x-%08x)\n", __func__, scp, host->host_no,
1918+ scp->device->channel, scp->device->id, scp->device->lun,
1919+ get_unaligned_be32(&((u32 *)scp->cmnd)[0]),
1920+ get_unaligned_be32(&((u32 *)scp->cmnd)[1]),
1921+ get_unaligned_be32(&((u32 *)scp->cmnd)[2]),
1922+ get_unaligned_be32(&((u32 *)scp->cmnd)[3]));
18481923
18491924 switch (cfg->state) {
18501925 case STATE_NORMAL:
@@ -1870,7 +1945,7 @@ static int cxlflash_eh_host_reset_handler(struct scsi_cmnd *scp) · 19 unmodified lines
18701945 break;
18711946 }
18721947
1873− pr_debug("%s: returning rc=%d\n", __func__, rc);
1948+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
18741949 return rc;
18751950 }
18761951
@@ -1936,8 +2011,7 @@ static ssize_t port0_show(struct device *dev, · 59 unmodified lines
19362011 struct device_attribute *attr,
19372012 char *buf)
19382013 {
1939− struct Scsi_Host *shost = class_to_shost(dev);
1940− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
2014+ struct cxlflash_cfg *cfg = shost_priv(class_to_shost(dev));
19412015 struct afu *afu = cfg->afu;
19422016
19432017 return cxlflash_show_port_status(0, afu, buf);
@@ -1955,8 +2029,7 @@ static ssize_t port1_show(struct device *dev, · 11 unmodified lines
19552029 struct device_attribute *attr,
19562030 char *buf)
19572031 {
1958− struct Scsi_Host *shost = class_to_shost(dev);
1959− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
2032+ struct cxlflash_cfg *cfg = shost_priv(class_to_shost(dev));
19602033 struct afu *afu = cfg->afu;
19612034
19622035 return cxlflash_show_port_status(1, afu, buf);
@@ -1973,8 +2046,7 @@ static ssize_t port1_show(struct device *dev, · 10 unmodified lines
19732046 static ssize_t lun_mode_show(struct device *dev,
19742047 struct device_attribute *attr, char *buf)
19752048 {
1976− struct Scsi_Host *shost = class_to_shost(dev);
1977− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
2049+ struct cxlflash_cfg *cfg = shost_priv(class_to_shost(dev));
19782050 struct afu *afu = cfg->afu;
19792051
19802052 return scnprintf(buf, PAGE_SIZE, "%u\n", afu->internal_lun);
@@ -2007,7 +2079,7 @@ static ssize_t lun_mode_store(struct device *dev, · 26 unmodified lines
20072079 const char *buf, size_t count)
20082080 {
20092081 struct Scsi_Host *shost = class_to_shost(dev);
2010− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
2082+ struct cxlflash_cfg *cfg = shost_priv(shost);
20112083 struct afu *afu = cfg->afu;
20122084 int rc;
20132085 u32 lun_mode;
@@ -2069,7 +2141,7 @@ static ssize_t cxlflash_show_port_lun_table(u32 port, · 55 unmodified lines
20692141
20702142 for (i = 0; i < CXLFLASH_NUM_VLUNS; i++)
20712143 bytes += scnprintf(buf + bytes, PAGE_SIZE - bytes,
2072− "%03d: %016llX\n", i, readq_be(&fc_port[i]));
2144+ "%03d: %016llx\n", i, readq_be(&fc_port[i]));
20732145 return bytes;
20742146 }
20752147
@@ -2085,8 +2157,7 @@ static ssize_t port0_lun_table_show(struct device *dev, · 9 unmodified lines
20852157 struct device_attribute *attr,
20862158 char *buf)
20872159 {
2088− struct Scsi_Host *shost = class_to_shost(dev);
2089− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
2160+ struct cxlflash_cfg *cfg = shost_priv(class_to_shost(dev));
20902161 struct afu *afu = cfg->afu;
20912162
20922163 return cxlflash_show_port_lun_table(0, afu, buf);
@@ -2104,8 +2175,7 @@ static ssize_t port1_lun_table_show(struct device *dev, · 11 unmodified lines
21042175 struct device_attribute *attr,
21052176 char *buf)
21062177 {
2107− struct Scsi_Host *shost = class_to_shost(dev);
2108− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
2178+ struct cxlflash_cfg *cfg = shost_priv(class_to_shost(dev));
21092179 struct afu *afu = cfg->afu;
21102180
21112181 return cxlflash_show_port_lun_table(1, afu, buf);
@@ -2250,7 +2320,6 @@ static void cxlflash_worker_thread(struct work_struct *work) · 138 unmodified lines
22502320
22512321 if (atomic_dec_if_positive(&cfg->scan_host_needed) >= 0)
22522322 scsi_scan_host(cfg->host);
2253− kref_put(&afu->mapcount, afu_unmap);
22542323 }
22552324
22562325 /**
@@ -2265,6 +2334,7 @@ static int cxlflash_probe(struct pci_dev *pdev, · 8 unmodified lines
22652334 {
22662335 struct Scsi_Host *host;
22672336 struct cxlflash_cfg *cfg = NULL;
2337+ struct device *dev = &pdev->dev;
22682338 struct dev_dependent_vals *ddv;
22692339 int rc = 0;
22702340
@@ -2276,8 +2346,7 @@ static int cxlflash_probe(struct pci_dev *pdev, · 5 unmodified lines
22762346
22772347 host = scsi_host_alloc(&driver_template, sizeof(struct cxlflash_cfg));
22782348 if (!host) {
2279− dev_err(&pdev->dev, "%s: call to scsi_host_alloc failed!\n",
2280− __func__);
2349+ dev_err(dev, "%s: scsi_host_alloc failed\n", __func__);
22812350 rc = -ENOMEM;
22822351 goto out;
22832352 }
@@ -2288,12 +2357,11 @@ static int cxlflash_probe(struct pci_dev *pdev, · 4 unmodified lines
22882357 host->unique_id = host->host_no;
22892358 host->max_cmd_len = CXLFLASH_MAX_CDB_LEN;
22902359
2291− cfg = (struct cxlflash_cfg *)host->hostdata;
2360+ cfg = shost_priv(host);
22922361 cfg->host = host;
22932362 rc = alloc_mem(cfg);
22942363 if (rc) {
2295− dev_err(&pdev->dev, "%s: call to alloc_mem failed!\n",
2296− __func__);
2364+ dev_err(dev, "%s: alloc_mem failed\n", __func__);
22972365 rc = -ENOMEM;
22982366 scsi_host_put(cfg->host);
22992367 goto out;
@@ -2334,30 +2402,27 @@ static int cxlflash_probe(struct pci_dev *pdev, · 34 unmodified lines
23342402
23352403 rc = init_pci(cfg);
23362404 if (rc) {
2337− dev_err(&pdev->dev, "%s: call to init_pci "
2338− "failed rc=%d!\n", __func__, rc);
2405+ dev_err(dev, "%s: init_pci failed rc=%d\n", __func__, rc);
23392406 goto out_remove;
23402407 }
23412408 cfg->init_state = INIT_STATE_PCI;
23422409
23432410 rc = init_afu(cfg);
23442411 if (rc) {
2345− dev_err(&pdev->dev, "%s: call to init_afu "
2346− "failed rc=%d!\n", __func__, rc);
2412+ dev_err(dev, "%s: init_afu failed rc=%d\n", __func__, rc);
23472413 goto out_remove;
23482414 }
23492415 cfg->init_state = INIT_STATE_AFU;
23502416
23512417 rc = init_scsi(cfg);
23522418 if (rc) {
2353− dev_err(&pdev->dev, "%s: call to init_scsi "
2354− "failed rc=%d!\n", __func__, rc);
2419+ dev_err(dev, "%s: init_scsi failed rc=%d\n", __func__, rc);
23552420 goto out_remove;
23562421 }
23572422 cfg->init_state = INIT_STATE_SCSI;
23582423
23592424 out:
2360− pr_debug("%s: returning rc=%d\n", __func__, rc);
2425+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
23612426 return rc;
23622427
23632428 out_remove:
@@ -2395,7 +2460,7 @@ static pci_ers_result_t cxlflash_pci_error_detected(struct pci_dev *pdev, · 31 unmodified lines
23952460 drain_ioctls(cfg);
23962461 rc = cxlflash_mark_contexts_error(cfg);
23972462 if (unlikely(rc))
2398− dev_err(dev, "%s: Failed to mark user contexts!(%d)\n",
2463+ dev_err(dev, "%s: Failed to mark user contexts rc=%d\n",
23992464 __func__, rc);
24002465 term_afu(cfg);
24012466 return PCI_ERS_RESULT_NEED_RESET;
@@ -2429,7 +2494,7 @@ static pci_ers_result_t cxlflash_pci_slot_reset(struct pci_dev *pdev) · 27 unmodified lines
24292494
24302495 rc = init_afu(cfg);
24312496 if (unlikely(rc)) {
2432− dev_err(dev, "%s: EEH recovery failed! (%d)\n", __func__, rc);
2497+ dev_err(dev, "%s: EEH recovery failed rc=%d\n", __func__, rc);
24332498 return PCI_ERS_RESULT_DISCONNECT;
24342499 }
24352500
@@ -2477,8 +2542,6 @@ static struct pci_driver cxlflash_driver = { · 41 unmodified lines
24772542 */
24782543 static int __init init_cxlflash(void)
24792544 {
2480− pr_info("%s: %s\n", __func__, CXLFLASH_ADAPTER_NAME);
2481−
24822545 cxlflash_list_init();
24832546
24842547 return pci_register_driver(&cxlflash_driver);
drivers/scsi/cxlflash/sislite.h+18−1
@@ -72,7 +72,10 @@ struct sisl_ioarcb { · 71 unmodified lines
7272 u16 timeout; /* in units specified by req_flags */
7373 u32 rsvd1;
7474 u8 cdb[16]; /* must be in big endian */
75− u64 reserved; /* Reserved area */
75+ union {
76+ u64 reserved; /* Reserved for IOARRIN mode */
77+ struct sisl_ioasa *ioasa; /* IOASA EA for SQ Mode */
78+ };
7679 } __packed;
7780
7881 struct sisl_rc {
@@ -260,6 +263,11 @@ struct sisl_host_map { · 181 unmodified lines
260263 __be64 cmd_room;
261264 __be64 ctx_ctrl; /* least significant byte or b56:63 is LISN# */
262265 __be64 mbox_w; /* restricted use */
266+ __be64 sq_start; /* Submission Queue (R/W): write sequence and */
267+ __be64 sq_end; /* inclusion semantics are the same as RRQ */
268+ __be64 sq_head; /* Submission Queue Head (R): for debugging */
269+ __be64 sq_tail; /* Submission Queue TAIL (R/W): next IOARCB */
270+ __be64 sq_ctx_reset; /* Submission Queue Context Reset (R/W) */
263271 };
264272
265273 /* per context provisioning & control MMIO */
@@ -348,6 +356,15 @@ struct sisl_global_regs { · 82 unmodified lines
348356 __be64 rsvd[0xf8];
349357 __le64 afu_version;
350358 __be64 interface_version;
359+#define SISL_INTVER_CAP_SHIFT 16
360+#define SISL_INTVER_MAJ_SHIFT 8
361+#define SISL_INTVER_CAP_MASK 0xFFFFFFFF00000000ULL
362+#define SISL_INTVER_MAJ_MASK 0x00000000FFFF0000ULL
363+#define SISL_INTVER_MIN_MASK 0x000000000000FFFFULL
364+#define SISL_INTVER_CAP_IOARRIN_CMD_MODE 0x800000000000ULL
365+#define SISL_INTVER_CAP_SQ_CMD_MODE 0x400000000000ULL
366+#define SISL_INTVER_CAP_RESERVED_CMD_MODE_A 0x200000000000ULL
367+#define SISL_INTVER_CAP_RESERVED_CMD_MODE_B 0x100000000000ULL
351368 };
352369
353370 #define CXLFLASH_NUM_FC_PORTS 2
drivers/scsi/cxlflash/superpipe.c+99−84
@@ -212,7 +212,7 @@ struct ctx_info *get_context(struct cxlflash_cfg *cfg, u64 rctxid, · 211 unmodified lines
212212 }
213213
214214 out:
215− dev_dbg(dev, "%s: rctxid=%016llX ctxinfo=%p ctxpid=%u pid=%u "
215+ dev_dbg(dev, "%s: rctxid=%016llx ctxinfo=%p ctxpid=%u pid=%u "
216216 "ctx_ctrl=%u\n", __func__, rctxid, ctxi, ctxpid, pid,
217217 ctx_ctrl);
218218
@@ -260,7 +260,7 @@ static int afu_attach(struct cxlflash_cfg *cfg, struct ctx_info *ctxi) · 41 unmodified lines
260260 writeq_be(val, &ctrl_map->ctx_cap);
261261 val = readq_be(&ctrl_map->ctx_cap);
262262 if (val != (SISL_CTX_CAP_READ_CMD | SISL_CTX_CAP_WRITE_CMD)) {
263− dev_err(dev, "%s: ctx may be closed val=%016llX\n",
263+ dev_err(dev, "%s: ctx may be closed val=%016llx\n",
264264 __func__, val);
265265 rc = -EAGAIN;
266266 goto out;
@@ -302,7 +302,7 @@ out: · 35 unmodified lines
302302 */
303303 static int read_cap16(struct scsi_device *sdev, struct llun_info *lli)
304304 {
305− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
305+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
306306 struct device *dev = &cfg->dev->dev;
307307 struct glun_info *gli = lli->parent;
308308 u8 *cmd_buf = NULL;
@@ -326,7 +326,7 @@ retry: · 17 unmodified lines
326326 scsi_cmd[1] = SAI_READ_CAPACITY_16; /* service action */
327327 put_unaligned_be32(CMD_BUFSIZE, &scsi_cmd[10]);
328328
329− dev_dbg(dev, "%s: %ssending cmd(0x%x)\n", __func__,
329+ dev_dbg(dev, "%s: %ssending cmd(%02x)\n", __func__,
330330 retry_cnt ? "re" : "", scsi_cmd[0]);
331331
332332 /* Drop the ioctl read semahpore across lengthy call */
@@ -336,7 +336,7 @@ retry: · 3 unmodified lines
336336 down_read(&cfg->ioctl_rwsem);
337337 rc = check_state(cfg);
338338 if (rc) {
339− dev_err(dev, "%s: Failed state! result=0x08%X\n",
339+ dev_err(dev, "%s: Failed state result=%08x\n",
340340 __func__, result);
341341 rc = -ENODEV;
342342 goto out;
@@ -378,7 +378,7 @@ retry: · 35 unmodified lines
378378 }
379379
380380 if (result) {
381− dev_err(dev, "%s: command failed, result=0x%x\n",
381+ dev_err(dev, "%s: command failed, result=%08x\n",
382382 __func__, result);
383383 rc = -EIO;
384384 goto out;
@@ -415,29 +415,32 @@ out: · 30 unmodified lines
415415 struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl,
416416 struct llun_info *lli)
417417 {
418+ struct cxlflash_cfg *cfg = ctxi->cfg;
419+ struct device *dev = &cfg->dev->dev;
418420 struct sisl_rht_entry *rhte = NULL;
419421
420422 if (unlikely(!ctxi->rht_start)) {
421− pr_debug("%s: Context does not have allocated RHT!\n",
423+ dev_dbg(dev, "%s: Context does not have allocated RHT\n",
422424 __func__);
423425 goto out;
424426 }
425427
426428 if (unlikely(rhndl >= MAX_RHT_PER_CONTEXT)) {
427− pr_debug("%s: Bad resource handle! (%d)\n", __func__, rhndl);
429+ dev_dbg(dev, "%s: Bad resource handle rhndl=%d\n",
430+ __func__, rhndl);
428431 goto out;
429432 }
430433
431434 if (unlikely(ctxi->rht_lun[rhndl] != lli)) {
432− pr_debug("%s: Bad resource handle LUN! (%d)\n",
433− __func__, rhndl);
435+ dev_dbg(dev, "%s: Bad resource handle LUN rhndl=%d\n",
436+ __func__, rhndl);
434437 goto out;
435438 }
436439
437440 rhte = &ctxi->rht_start[rhndl];
438441 if (unlikely(rhte->nmask == 0)) {
439− pr_debug("%s: Unopened resource handle! (%d)\n",
440− __func__, rhndl);
442+ dev_dbg(dev, "%s: Unopened resource handle rhndl=%d\n",
443+ __func__, rhndl);
441444 rhte = NULL;
442445 goto out;
443446 }
@@ -456,6 +459,8 @@ out: · 12 unmodified lines
456459 struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi,
457460 struct llun_info *lli)
458461 {
462+ struct cxlflash_cfg *cfg = ctxi->cfg;
463+ struct device *dev = &cfg->dev->dev;
459464 struct sisl_rht_entry *rhte = NULL;
460465 int i;
461466
@@ -470,7 +475,7 @@ struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi, · 8 unmodified lines
470475 if (likely(rhte))
471476 ctxi->rht_lun[i] = lli;
472477
473− pr_debug("%s: returning rhte=%p (%d)\n", __func__, rhte, i);
478+ dev_dbg(dev, "%s: returning rhte=%p index=%d\n", __func__, rhte, i);
474479 return rhte;
475480 }
476481
@@ -547,7 +552,7 @@ int cxlflash_lun_attach(struct glun_info *gli, enum lun_mode mode, bool locked) · 70 unmodified lines
547552 if (gli->mode == MODE_NONE)
548553 gli->mode = mode;
549554 else if (gli->mode != mode) {
550− pr_debug("%s: LUN operating in mode %d, requested mode %d\n",
555+ pr_debug("%s: gli_mode=%d requested_mode=%d\n",
551556 __func__, gli->mode, mode);
552557 rc = -EINVAL;
553558 goto out;
@@ -605,7 +610,7 @@ int _cxlflash_disk_release(struct scsi_device *sdev, · 51 unmodified lines
605610 struct ctx_info *ctxi,
606611 struct dk_cxlflash_release *release)
607612 {
608− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
613+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
609614 struct device *dev = &cfg->dev->dev;
610615 struct llun_info *lli = sdev->hostdata;
611616 struct glun_info *gli = lli->parent;
@@ -622,13 +627,13 @@ int _cxlflash_disk_release(struct scsi_device *sdev, · 10 unmodified lines
622627 struct sisl_rht_entry *rhte;
623628 struct sisl_rht_entry_f1 *rhte_f1;
624629
625− dev_dbg(dev, "%s: ctxid=%llu rhndl=0x%llx gli->mode=%u gli->users=%u\n",
630+ dev_dbg(dev, "%s: ctxid=%llu rhndl=%llu gli->mode=%u gli->users=%u\n",
626631 __func__, ctxid, release->rsrc_handle, gli->mode, gli->users);
627632
628633 if (!ctxi) {
629634 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
630635 if (unlikely(!ctxi)) {
631− dev_dbg(dev, "%s: Bad context! (%llu)\n",
636+ dev_dbg(dev, "%s: Bad context ctxid=%llu\n",
632637 __func__, ctxid);
633638 rc = -EINVAL;
634639 goto out;
@@ -639,7 +644,7 @@ int _cxlflash_disk_release(struct scsi_device *sdev, · 4 unmodified lines
639644
640645 rhte = get_rhte(ctxi, rhndl, lli);
641646 if (unlikely(!rhte)) {
642− dev_dbg(dev, "%s: Bad resource handle! (%d)\n",
647+ dev_dbg(dev, "%s: Bad resource handle rhndl=%d\n",
643648 __func__, rhndl);
644649 rc = -EINVAL;
645650 goto out;
@@ -758,13 +763,13 @@ static struct ctx_info *create_context(struct cxlflash_cfg *cfg) · 112 unmodified lines
758763 lli = kzalloc((MAX_RHT_PER_CONTEXT * sizeof(*lli)), GFP_KERNEL);
759764 ws = kzalloc((MAX_RHT_PER_CONTEXT * sizeof(*ws)), GFP_KERNEL);
760765 if (unlikely(!ctxi || !lli || !ws)) {
761− dev_err(dev, "%s: Unable to allocate context!\n", __func__);
766+ dev_err(dev, "%s: Unable to allocate context\n", __func__);
762767 goto err;
763768 }
764769
765770 rhte = (struct sisl_rht_entry *)get_zeroed_page(GFP_KERNEL);
766771 if (unlikely(!rhte)) {
767− dev_err(dev, "%s: Unable to allocate RHT!\n", __func__);
772+ dev_err(dev, "%s: Unable to allocate RHT\n", __func__);
768773 goto err;
769774 }
770775
@@ -858,7 +863,7 @@ static int _cxlflash_disk_detach(struct scsi_device *sdev, · 87 unmodified lines
858863 struct ctx_info *ctxi,
859864 struct dk_cxlflash_detach *detach)
860865 {
861− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
866+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
862867 struct device *dev = &cfg->dev->dev;
863868 struct llun_info *lli = sdev->hostdata;
864869 struct lun_access *lun_access, *t;
@@ -875,7 +880,7 @@ static int _cxlflash_disk_detach(struct scsi_device *sdev, · 10 unmodified lines
875880 if (!ctxi) {
876881 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
877882 if (unlikely(!ctxi)) {
878− dev_dbg(dev, "%s: Bad context! (%llu)\n",
883+ dev_dbg(dev, "%s: Bad context ctxid=%llu\n",
879884 __func__, ctxid);
880885 rc = -EINVAL;
881886 goto out;
@@ -964,7 +969,7 @@ static int cxlflash_cxl_release(struct inode *inode, struct file *file) · 82 unmodified lines
964969
965970 ctxid = cxl_process_element(ctx);
966971 if (unlikely(ctxid < 0)) {
967− dev_err(dev, "%s: Context %p was closed! (%d)\n",
972+ dev_err(dev, "%s: Context %p was closed ctxid=%d\n",
968973 __func__, ctx, ctxid);
969974 goto out;
970975 }
@@ -973,18 +978,18 @@ static int cxlflash_cxl_release(struct inode *inode, struct file *file) · 2 unmodified lines
973978 if (unlikely(!ctxi)) {
974979 ctxi = get_context(cfg, ctxid, file, ctrl | CTX_CTRL_CLONE);
975980 if (!ctxi) {
976− dev_dbg(dev, "%s: Context %d already free!\n",
981+ dev_dbg(dev, "%s: ctxid=%d already free\n",
977982 __func__, ctxid);
978983 goto out_release;
979984 }
980985
981− dev_dbg(dev, "%s: Another process owns context %d!\n",
986+ dev_dbg(dev, "%s: Another process owns ctxid=%d\n",
982987 __func__, ctxid);
983988 put_context(ctxi);
984989 goto out;
985990 }
986991
987− dev_dbg(dev, "%s: close for context %d\n", __func__, ctxid);
992+ dev_dbg(dev, "%s: close for ctxid=%d\n", __func__, ctxid);
988993
989994 detach.context_id = ctxi->ctxid;
990995 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list)
@@ -1011,17 +1016,20 @@ static void unmap_context(struct ctx_info *ctxi) · 20 unmodified lines
10111016
10121017 /**
10131018 * get_err_page() - obtains and allocates the error notification page
1019+ * @cfg: Internal structure associated with the host.
10141020 *
10151021 * Return: error notification page on success, NULL on failure
10161022 */
1017−static struct page *get_err_page(void)
1023+static struct page *get_err_page(struct cxlflash_cfg *cfg)
10181024 {
10191025 struct page *err_page = global.err_page;
1026+ struct device *dev = &cfg->dev->dev;
10201027
10211028 if (unlikely(!err_page)) {
10221029 err_page = alloc_page(GFP_KERNEL);
10231030 if (unlikely(!err_page)) {
1024− pr_err("%s: Unable to allocate err_page!\n", __func__);
1031+ dev_err(dev, "%s: Unable to allocate err_page\n",
1032+ __func__);
10251033 goto out;
10261034 }
10271035
@@ -1039,7 +1047,7 @@ static struct page *get_err_page(void) · 11 unmodified lines
10391047 }
10401048
10411049 out:
1042− pr_debug("%s: returning err_page=%p\n", __func__, err_page);
1050+ dev_dbg(dev, "%s: returning err_page=%p\n", __func__, err_page);
10431051 return err_page;
10441052 }
10451053
@@ -1074,14 +1082,14 @@ static int cxlflash_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) · 28 unmodified lines
10741082
10751083 ctxid = cxl_process_element(ctx);
10761084 if (unlikely(ctxid < 0)) {
1077− dev_err(dev, "%s: Context %p was closed! (%d)\n",
1085+ dev_err(dev, "%s: Context %p was closed ctxid=%d\n",
10781086 __func__, ctx, ctxid);
10791087 goto err;
10801088 }
10811089
10821090 ctxi = get_context(cfg, ctxid, file, ctrl);
10831091 if (unlikely(!ctxi)) {
1084− dev_dbg(dev, "%s: Bad context! (%d)\n", __func__, ctxid);
1092+ dev_dbg(dev, "%s: Bad context ctxid=%d\n", __func__, ctxid);
10851093 goto err;
10861094 }
10871095
@@ -1091,13 +1099,12 @@ static int cxlflash_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) · 3 unmodified lines
10911099 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
10921100 rc = ctxi->cxl_mmap_vmops->fault(vma, vmf);
10931101 } else {
1094− dev_dbg(dev, "%s: err recovery active, use err_page!\n",
1102+ dev_dbg(dev, "%s: err recovery active, use err_page\n",
10951103 __func__);
10961104
1097− err_page = get_err_page();
1105+ err_page = get_err_page(cfg);
10981106 if (unlikely(!err_page)) {
1099− dev_err(dev, "%s: Could not obtain error page!\n",
1100− __func__);
1107+ dev_err(dev, "%s: Could not get err_page\n", __func__);
11011108 rc = VM_FAULT_RETRY;
11021109 goto out;
11031110 }
@@ -1147,7 +1154,7 @@ static int cxlflash_cxl_mmap(struct file *file, struct vm_area_struct *vma) · 43 unmodified lines
11471154
11481155 ctxid = cxl_process_element(ctx);
11491156 if (unlikely(ctxid < 0)) {
1150− dev_err(dev, "%s: Context %p was closed! (%d)\n",
1157+ dev_err(dev, "%s: Context %p was closed ctxid=%d\n",
11511158 __func__, ctx, ctxid);
11521159 rc = -EIO;
11531160 goto out;
@@ -1155,7 +1162,7 @@ static int cxlflash_cxl_mmap(struct file *file, struct vm_area_struct *vma) · 1 unmodified line
11551162
11561163 ctxi = get_context(cfg, ctxid, file, ctrl);
11571164 if (unlikely(!ctxi)) {
1158− dev_dbg(dev, "%s: Bad context! (%d)\n", __func__, ctxid);
1165+ dev_dbg(dev, "%s: Bad context ctxid=%d\n", __func__, ctxid);
11591166 rc = -EIO;
11601167 goto out;
11611168 }
@@ -1251,7 +1258,7 @@ retry: · 89 unmodified lines
12511258 break;
12521259 goto retry;
12531260 case STATE_FAILTERM:
1254− dev_dbg(dev, "%s: Failed/Terminating!\n", __func__);
1261+ dev_dbg(dev, "%s: Failed/Terminating\n", __func__);
12551262 rc = -ENODEV;
12561263 break;
12571264 default:
@@ -1276,7 +1283,7 @@ retry: · 18 unmodified lines
12761283 static int cxlflash_disk_attach(struct scsi_device *sdev,
12771284 struct dk_cxlflash_attach *attach)
12781285 {
1279− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1286+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
12801287 struct device *dev = &cfg->dev->dev;
12811288 struct afu *afu = cfg->afu;
12821289 struct llun_info *lli = sdev->hostdata;
@@ -1287,6 +1294,7 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 4 unmodified lines
12871294 int rc = 0;
12881295 u32 perms;
12891296 int ctxid = -1;
1297+ u64 flags = 0UL;
12901298 u64 rctxid = 0UL;
12911299 struct file *file = NULL;
12921300
@@ -1302,24 +1310,24 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 9 unmodified lines
13021310 }
13031311
13041312 if (gli->max_lba == 0) {
1305− dev_dbg(dev, "%s: No capacity info for this LUN (%016llX)\n",
1313+ dev_dbg(dev, "%s: No capacity info for LUN=%016llx\n",
13061314 __func__, lli->lun_id[sdev->channel]);
13071315 rc = read_cap16(sdev, lli);
13081316 if (rc) {
1309− dev_err(dev, "%s: Invalid device! (%d)\n",
1317+ dev_err(dev, "%s: Invalid device rc=%d\n",
13101318 __func__, rc);
13111319 rc = -ENODEV;
13121320 goto out;
13131321 }
1314− dev_dbg(dev, "%s: LBA = %016llX\n", __func__, gli->max_lba);
1315− dev_dbg(dev, "%s: BLK_LEN = %08X\n", __func__, gli->blk_len);
1322+ dev_dbg(dev, "%s: LBA = %016llx\n", __func__, gli->max_lba);
1323+ dev_dbg(dev, "%s: BLK_LEN = %08x\n", __func__, gli->blk_len);
13161324 }
13171325
13181326 if (attach->hdr.flags & DK_CXLFLASH_ATTACH_REUSE_CONTEXT) {
13191327 rctxid = attach->context_id;
13201328 ctxi = get_context(cfg, rctxid, NULL, 0);
13211329 if (!ctxi) {
1322− dev_dbg(dev, "%s: Bad context! (%016llX)\n",
1330+ dev_dbg(dev, "%s: Bad context rctxid=%016llx\n",
13231331 __func__, rctxid);
13241332 rc = -EINVAL;
13251333 goto out;
@@ -1327,7 +1335,7 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 1 unmodified line
13271335
13281336 list_for_each_entry(lun_access, &ctxi->luns, list)
13291337 if (lun_access->lli == lli) {
1330− dev_dbg(dev, "%s: Already attached!\n",
1338+ dev_dbg(dev, "%s: Already attached\n",
13311339 __func__);
13321340 rc = -EINVAL;
13331341 goto out;
@@ -1336,13 +1344,13 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 2 unmodified lines
13361344
13371345 rc = scsi_device_get(sdev);
13381346 if (unlikely(rc)) {
1339− dev_err(dev, "%s: Unable to get sdev reference!\n", __func__);
1347+ dev_err(dev, "%s: Unable to get sdev reference\n", __func__);
13401348 goto out;
13411349 }
13421350
13431351 lun_access = kzalloc(sizeof(*lun_access), GFP_KERNEL);
13441352 if (unlikely(!lun_access)) {
1345− dev_err(dev, "%s: Unable to allocate lun_access!\n", __func__);
1353+ dev_err(dev, "%s: Unable to allocate lun_access\n", __func__);
13461354 rc = -ENOMEM;
13471355 goto err;
13481356 }
@@ -1352,7 +1360,7 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 3 unmodified lines
13521360
13531361 /* Non-NULL context indicates reuse (another context reference) */
13541362 if (ctxi) {
1355− dev_dbg(dev, "%s: Reusing context for LUN! (%016llX)\n",
1363+ dev_dbg(dev, "%s: Reusing context for LUN rctxid=%016llx\n",
13561364 __func__, rctxid);
13571365 kref_get(&ctxi->kref);
13581366 list_add(&lun_access->list, &ctxi->luns);
@@ -1361,7 +1369,7 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 2 unmodified lines
13611369
13621370 ctxi = create_context(cfg);
13631371 if (unlikely(!ctxi)) {
1364− dev_err(dev, "%s: Failed to create context! (%d)\n",
1372+ dev_err(dev, "%s: Failed to create context ctxid=%d\n",
13651373 __func__, ctxid);
13661374 goto err;
13671375 }
@@ -1387,7 +1395,7 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 19 unmodified lines
13871395
13881396 ctxid = cxl_process_element(ctx);
13891397 if (unlikely((ctxid >= MAX_CONTEXT) || (ctxid < 0))) {
1390− dev_err(dev, "%s: ctxid (%d) invalid!\n", __func__, ctxid);
1398+ dev_err(dev, "%s: ctxid=%d invalid\n", __func__, ctxid);
13911399 rc = -EPERM;
13921400 goto err;
13931401 }
@@ -1426,10 +1434,11 @@ static int cxlflash_disk_attach(struct scsi_device *sdev, · 32 unmodified lines
14261434
14271435 out_attach:
14281436 if (fd != -1)
1429− attach->hdr.return_flags = DK_CXLFLASH_APP_CLOSE_ADAP_FD;
1430− else
1431− attach->hdr.return_flags = 0;
1437+ flags |= DK_CXLFLASH_APP_CLOSE_ADAP_FD;
1438+ if (afu_is_sq_cmd_mode(afu))
1439+ flags |= DK_CXLFLASH_CONTEXT_SQ_CMD_MODE;
14321440
1441+ attach->hdr.return_flags = flags;
14331442 attach->context_id = ctxi->ctxid;
14341443 attach->block_size = gli->blk_len;
14351444 attach->mmio_size = sizeof(afu->afu_map->hosts[0].harea);
@@ -1520,7 +1529,7 @@ static int recover_context(struct cxlflash_cfg *cfg, · 84 unmodified lines
15201529
15211530 ctxid = cxl_process_element(ctx);
15221531 if (unlikely((ctxid >= MAX_CONTEXT) || (ctxid < 0))) {
1523− dev_err(dev, "%s: ctxid (%d) invalid!\n", __func__, ctxid);
1532+ dev_err(dev, "%s: ctxid=%d invalid\n", __func__, ctxid);
15241533 rc = -EPERM;
15251534 goto err2;
15261535 }
@@ -1611,12 +1620,13 @@ err1: · 84 unmodified lines
16111620 static int cxlflash_afu_recover(struct scsi_device *sdev,
16121621 struct dk_cxlflash_recover_afu *recover)
16131622 {
1614− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1623+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
16151624 struct device *dev = &cfg->dev->dev;
16161625 struct llun_info *lli = sdev->hostdata;
16171626 struct afu *afu = cfg->afu;
16181627 struct ctx_info *ctxi = NULL;
16191628 struct mutex *mutex = &cfg->ctx_recovery_mutex;
1629+ u64 flags;
16201630 u64 ctxid = DECODE_CTXID(recover->context_id),
16211631 rctxid = recover->context_id;
16221632 long reg;
@@ -1632,19 +1642,19 @@ static int cxlflash_afu_recover(struct scsi_device *sdev, · 9 unmodified lines
16321642 goto out;
16331643 rc = check_state(cfg);
16341644 if (rc) {
1635− dev_err(dev, "%s: Failed state! rc=%d\n", __func__, rc);
1645+ dev_err(dev, "%s: Failed state rc=%d\n", __func__, rc);
16361646 rc = -ENODEV;
16371647 goto out;
16381648 }
16391649
1640− dev_dbg(dev, "%s: reason 0x%016llX rctxid=%016llX\n",
1650+ dev_dbg(dev, "%s: reason=%016llx rctxid=%016llx\n",
16411651 __func__, recover->reason, rctxid);
16421652
16431653 retry:
16441654 /* Ensure that this process is attached to the context */
16451655 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
16461656 if (unlikely(!ctxi)) {
1647− dev_dbg(dev, "%s: Bad context! (%llu)\n", __func__, ctxid);
1657+ dev_dbg(dev, "%s: Bad context ctxid=%llu\n", __func__, ctxid);
16481658 rc = -EINVAL;
16491659 goto out;
16501660 }
@@ -1653,12 +1663,12 @@ retry: · 2 unmodified lines
16531663 retry_recover:
16541664 rc = recover_context(cfg, ctxi, &new_adap_fd);
16551665 if (unlikely(rc)) {
1656− dev_err(dev, "%s: Recovery failed for context %llu (rc=%d)\n",
1666+ dev_err(dev, "%s: Recovery failed ctxid=%llu rc=%d\n",
16571667 __func__, ctxid, rc);
16581668 if ((rc == -ENODEV) &&
16591669 ((atomic_read(&cfg->recovery_threads) > 1) ||
16601670 (lretry--))) {
1661− dev_dbg(dev, "%s: Going to try again!\n",
1671+ dev_dbg(dev, "%s: Going to try again\n",
16621672 __func__);
16631673 mutex_unlock(mutex);
16641674 msleep(100);
@@ -1672,11 +1682,16 @@ retry_recover: · 7 unmodified lines
16721682 }
16731683
16741684 ctxi->err_recovery_active = false;
1685+
1686+ flags = DK_CXLFLASH_APP_CLOSE_ADAP_FD |
1687+ DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET;
1688+ if (afu_is_sq_cmd_mode(afu))
1689+ flags |= DK_CXLFLASH_CONTEXT_SQ_CMD_MODE;
1690+
1691+ recover->hdr.return_flags = flags;
16751692 recover->context_id = ctxi->ctxid;
16761693 recover->adap_fd = new_adap_fd;
16771694 recover->mmio_size = sizeof(afu->afu_map->hosts[0].harea);
1678− recover->hdr.return_flags = DK_CXLFLASH_APP_CLOSE_ADAP_FD |
1679− DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET;
16801695 goto out;
16811696 }
16821697
@@ -1699,7 +1714,7 @@ retry_recover: · 16 unmodified lines
16991714 goto retry;
17001715 }
17011716
1702− dev_dbg(dev, "%s: MMIO working, no recovery required!\n", __func__);
1717+ dev_dbg(dev, "%s: MMIO working, no recovery required\n", __func__);
17031718 out:
17041719 if (likely(ctxi))
17051720 put_context(ctxi);
@@ -1718,7 +1733,7 @@ out: · 12 unmodified lines
17181733 static int process_sense(struct scsi_device *sdev,
17191734 struct dk_cxlflash_verify *verify)
17201735 {
1721− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1736+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
17221737 struct device *dev = &cfg->dev->dev;
17231738 struct llun_info *lli = sdev->hostdata;
17241739 struct glun_info *gli = lli->parent;
@@ -1729,7 +1744,7 @@ static int process_sense(struct scsi_device *sdev, · 4 unmodified lines
17291744 rc = scsi_normalize_sense((const u8 *)&verify->sense_data,
17301745 DK_CXLFLASH_VERIFY_SENSE_LEN, &sshdr);
17311746 if (!rc) {
1732− dev_err(dev, "%s: Failed to normalize sense data!\n", __func__);
1747+ dev_err(dev, "%s: Failed to normalize sense data\n", __func__);
17331748 rc = -EINVAL;
17341749 goto out;
17351750 }
@@ -1785,7 +1800,7 @@ static int cxlflash_disk_verify(struct scsi_device *sdev, · 49 unmodified lines
17851800 {
17861801 int rc = 0;
17871802 struct ctx_info *ctxi = NULL;
1788− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1803+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
17891804 struct device *dev = &cfg->dev->dev;
17901805 struct llun_info *lli = sdev->hostdata;
17911806 struct glun_info *gli = lli->parent;
@@ -1795,20 +1810,20 @@ static int cxlflash_disk_verify(struct scsi_device *sdev, · 3 unmodified lines
17951810 rctxid = verify->context_id;
17961811 u64 last_lba = 0;
17971812
1798− dev_dbg(dev, "%s: ctxid=%llu rhndl=%016llX, hint=%016llX, "
1799− "flags=%016llX\n", __func__, ctxid, verify->rsrc_handle,
1813+ dev_dbg(dev, "%s: ctxid=%llu rhndl=%016llx, hint=%016llx, "
1814+ "flags=%016llx\n", __func__, ctxid, verify->rsrc_handle,
18001815 verify->hint, verify->hdr.flags);
18011816
18021817 ctxi = get_context(cfg, rctxid, lli, 0);
18031818 if (unlikely(!ctxi)) {
1804− dev_dbg(dev, "%s: Bad context! (%llu)\n", __func__, ctxid);
1819+ dev_dbg(dev, "%s: Bad context ctxid=%llu\n", __func__, ctxid);
18051820 rc = -EINVAL;
18061821 goto out;
18071822 }
18081823
18091824 rhte = get_rhte(ctxi, rhndl, lli);
18101825 if (unlikely(!rhte)) {
1811− dev_dbg(dev, "%s: Bad resource handle! (%d)\n",
1826+ dev_dbg(dev, "%s: Bad resource handle rhndl=%d\n",
18121827 __func__, rhndl);
18131828 rc = -EINVAL;
18141829 goto out;
@@ -1855,7 +1870,7 @@ static int cxlflash_disk_verify(struct scsi_device *sdev, · 40 unmodified lines
18551870 out:
18561871 if (likely(ctxi))
18571872 put_context(ctxi);
1858− dev_dbg(dev, "%s: returning rc=%d llba=%llX\n",
1873+ dev_dbg(dev, "%s: returning rc=%d llba=%llx\n",
18591874 __func__, rc, verify->last_lba);
18601875 return rc;
18611876 }
@@ -1907,7 +1922,7 @@ static char *decode_ioctl(int cmd) · 45 unmodified lines
19071922 */
19081923 static int cxlflash_disk_direct_open(struct scsi_device *sdev, void *arg)
19091924 {
1910− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1925+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
19111926 struct device *dev = &cfg->dev->dev;
19121927 struct afu *afu = cfg->afu;
19131928 struct llun_info *lli = sdev->hostdata;
@@ -1927,25 +1942,25 @@ static int cxlflash_disk_direct_open(struct scsi_device *sdev, void *arg) · 13 unmodified lines
19271942 struct ctx_info *ctxi = NULL;
19281943 struct sisl_rht_entry *rhte = NULL;
19291944
1930− pr_debug("%s: ctxid=%llu ls=0x%llx\n", __func__, ctxid, lun_size);
1945+ dev_dbg(dev, "%s: ctxid=%llu ls=%llu\n", __func__, ctxid, lun_size);
19311946
19321947 rc = cxlflash_lun_attach(gli, MODE_PHYSICAL, false);
19331948 if (unlikely(rc)) {
1934− dev_dbg(dev, "%s: Failed to attach to LUN! (PHYSICAL)\n",
1935− __func__);
1949+ dev_dbg(dev, "%s: Failed attach to LUN (PHYSICAL)\n", __func__);
19361950 goto out;
19371951 }
19381952
19391953 ctxi = get_context(cfg, rctxid, lli, 0);
19401954 if (unlikely(!ctxi)) {
1941− dev_dbg(dev, "%s: Bad context! (%llu)\n", __func__, ctxid);
1955+ dev_dbg(dev, "%s: Bad context ctxid=%llu\n", __func__, ctxid);
19421956 rc = -EINVAL;
19431957 goto err1;
19441958 }
19451959
19461960 rhte = rhte_checkout(ctxi, lli);
19471961 if (unlikely(!rhte)) {
1948− dev_dbg(dev, "%s: too many opens for this context\n", __func__);
1962+ dev_dbg(dev, "%s: Too many opens ctxid=%lld\n",
1963+ __func__, ctxid);
19491964 rc = -EMFILE; /* too many opens */
19501965 goto err1;
19511966 }
@@ -1963,7 +1978,7 @@ static int cxlflash_disk_direct_open(struct scsi_device *sdev, void *arg) · 11 unmodified lines
19631978 out:
19641979 if (likely(ctxi))
19651980 put_context(ctxi);
1966− dev_dbg(dev, "%s: returning handle 0x%llx rc=%d llba %lld\n",
1981+ dev_dbg(dev, "%s: returning handle=%llu rc=%d llba=%llu\n",
19671982 __func__, rsrc_handle, rc, last_lba);
19681983 return rc;
19691984
@@ -1985,7 +2000,7 @@ err1: · 15 unmodified lines
19852000 */
19862001 static int ioctl_common(struct scsi_device *sdev, int cmd)
19872002 {
1988− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
2003+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
19892004 struct device *dev = &cfg->dev->dev;
19902005 struct llun_info *lli = sdev->hostdata;
19912006 int rc = 0;
@@ -2002,7 +2017,7 @@ static int ioctl_common(struct scsi_device *sdev, int cmd) · 10 unmodified lines
20022017 case DK_CXLFLASH_VLUN_RESIZE:
20032018 case DK_CXLFLASH_RELEASE:
20042019 case DK_CXLFLASH_DETACH:
2005− dev_dbg(dev, "%s: Command override! (%d)\n",
2020+ dev_dbg(dev, "%s: Command override rc=%d\n",
20062021 __func__, rc);
20072022 rc = 0;
20082023 break;
@@ -2032,7 +2047,7 @@ int cxlflash_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) · 23 unmodified lines
20322047 {
20332048 typedef int (*sioctl) (struct scsi_device *, void *);
20342049
2035− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
2050+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
20362051 struct device *dev = &cfg->dev->dev;
20372052 struct afu *afu = cfg->afu;
20382053 struct dk_cxlflash_hdr *hdr;
@@ -2111,7 +2126,7 @@ int cxlflash_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) · 72 unmodified lines
21112126 }
21122127
21132128 if (unlikely(copy_from_user(&buf, arg, size))) {
2114− dev_err(dev, "%s: copy_from_user() fail! "
2129+ dev_err(dev, "%s: copy_from_user() fail "
21152130 "size=%lu cmd=%d (%s) arg=%p\n",
21162131 __func__, size, cmd, decode_ioctl(cmd), arg);
21172132 rc = -EFAULT;
@@ -2127,7 +2142,7 @@ int cxlflash_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) · 9 unmodified lines
21272142 }
21282143
21292144 if (hdr->rsvd[0] || hdr->rsvd[1] || hdr->rsvd[2] || hdr->return_flags) {
2130− dev_dbg(dev, "%s: Reserved/rflags populated!\n", __func__);
2145+ dev_dbg(dev, "%s: Reserved/rflags populated\n", __func__);
21312146 rc = -EINVAL;
21322147 goto cxlflash_ioctl_exit;
21332148 }
@@ -2135,7 +2150,7 @@ int cxlflash_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) · 1 unmodified line
21352150 rc = do_ioctl(sdev, (void *)&buf);
21362151 if (likely(!rc))
21372152 if (unlikely(copy_to_user(arg, &buf, size))) {
2138− dev_err(dev, "%s: copy_to_user() fail! "
2153+ dev_err(dev, "%s: copy_to_user() fail "
21392154 "size=%lu cmd=%d (%s) arg=%p\n",
21402155 __func__, size, cmd, decode_ioctl(cmd), arg);
21412156 rc = -EFAULT;
drivers/scsi/cxlflash/vlun.c+90−79
@@ -66,8 +66,8 @@ static int ba_init(struct ba_lun *ba_lun) · 65 unmodified lines
6666 int last_word_underflow = 0;
6767 u64 *lam;
6868
69− pr_debug("%s: Initializing LUN: lun_id = %llX, "
70− "ba_lun->lsize = %lX, ba_lun->au_size = %lX\n",
69+ pr_debug("%s: Initializing LUN: lun_id=%016llx "
70+ "ba_lun->lsize=%lx ba_lun->au_size=%lX\n",
7171 __func__, ba_lun->lun_id, ba_lun->lsize, ba_lun->au_size);
7272
7373 /* Calculate bit map size */
@@ -80,7 +80,7 @@ static int ba_init(struct ba_lun *ba_lun) · 6 unmodified lines
8080 /* Allocate lun information container */
8181 bali = kzalloc(sizeof(struct ba_lun_info), GFP_KERNEL);
8282 if (unlikely(!bali)) {
83− pr_err("%s: Failed to allocate lun_info for lun_id %llX\n",
83+ pr_err("%s: Failed to allocate lun_info lun_id=%016llx\n",
8484 __func__, ba_lun->lun_id);
8585 return -ENOMEM;
8686 }
@@ -96,7 +96,7 @@ static int ba_init(struct ba_lun *ba_lun) · 9 unmodified lines
9696 GFP_KERNEL);
9797 if (unlikely(!bali->lun_alloc_map)) {
9898 pr_err("%s: Failed to allocate lun allocation map: "
99− "lun_id = %llX\n", __func__, ba_lun->lun_id);
99+ "lun_id=%016llx\n", __func__, ba_lun->lun_id);
100100 kfree(bali);
101101 return -ENOMEM;
102102 }
@@ -125,7 +125,7 @@ static int ba_init(struct ba_lun *ba_lun) · 22 unmodified lines
125125 bali->aun_clone_map = kzalloc((bali->total_aus * sizeof(u8)),
126126 GFP_KERNEL);
127127 if (unlikely(!bali->aun_clone_map)) {
128− pr_err("%s: Failed to allocate clone map: lun_id = %llX\n",
128+ pr_err("%s: Failed to allocate clone map: lun_id=%016llx\n",
129129 __func__, ba_lun->lun_id);
130130 kfree(bali->lun_alloc_map);
131131 kfree(bali);
@@ -136,7 +136,7 @@ static int ba_init(struct ba_lun *ba_lun) · 4 unmodified lines
136136 ba_lun->ba_lun_handle = bali;
137137
138138 pr_debug("%s: Successfully initialized the LUN: "
139− "lun_id = %llX, bitmap size = %X, free_aun_cnt = %llX\n",
139+ "lun_id=%016llx bitmap size=%x, free_aun_cnt=%llx\n",
140140 __func__, ba_lun->lun_id, bali->lun_bmap_size,
141141 bali->free_aun_cnt);
142142 return 0;
@@ -165,10 +165,9 @@ static int find_free_range(u32 low, · 22 unmodified lines
165165 num_bits = (sizeof(*lam) * BITS_PER_BYTE);
166166 bit_pos = find_first_bit(lam, num_bits);
167167
168− pr_devel("%s: Found free bit %llX in LUN "
169− "map entry %llX at bitmap index = %X\n",
170− __func__, bit_pos, bali->lun_alloc_map[i],
171− i);
168+ pr_devel("%s: Found free bit %llu in LUN "
169+ "map entry %016llx at bitmap index = %d\n",
170+ __func__, bit_pos, bali->lun_alloc_map[i], i);
172171
173172 *bit_word = i;
174173 bali->free_aun_cnt--;
@@ -194,11 +193,11 @@ static u64 ba_alloc(struct ba_lun *ba_lun) · 19 unmodified lines
194193 bali = ba_lun->ba_lun_handle;
195194
196195 pr_debug("%s: Received block allocation request: "
197− "lun_id = %llX, free_aun_cnt = %llX\n",
196+ "lun_id=%016llx free_aun_cnt=%llx\n",
198197 __func__, ba_lun->lun_id, bali->free_aun_cnt);
199198
200199 if (bali->free_aun_cnt == 0) {
201− pr_debug("%s: No space left on LUN: lun_id = %llX\n",
200+ pr_debug("%s: No space left on LUN: lun_id=%016llx\n",
202201 __func__, ba_lun->lun_id);
203202 return -1ULL;
204203 }
@@ -212,7 +211,7 @@ static u64 ba_alloc(struct ba_lun *ba_lun) · 7 unmodified lines
212211 bali, &bit_word);
213212 if (bit_pos == -1) {
214213 pr_debug("%s: Could not find an allocation unit on LUN:"
215− " lun_id = %llX\n", __func__, ba_lun->lun_id);
214+ " lun_id=%016llx\n", __func__, ba_lun->lun_id);
216215 return -1ULL;
217216 }
218217 }
@@ -223,8 +222,8 @@ static u64 ba_alloc(struct ba_lun *ba_lun) · 4 unmodified lines
223222 else
224223 bali->free_curr_idx = bit_word;
225224
226− pr_debug("%s: Allocating AU number %llX, on lun_id %llX, "
227− "free_aun_cnt = %llX\n", __func__,
225+ pr_debug("%s: Allocating AU number=%llx lun_id=%016llx "
226+ "free_aun_cnt=%llx\n", __func__,
228227 ((bit_word * BITS_PER_LONG) + bit_pos), ba_lun->lun_id,
229228 bali->free_aun_cnt);
230229
@@ -266,18 +265,18 @@ static int ba_free(struct ba_lun *ba_lun, u64 to_free) · 35 unmodified lines
266265 bali = ba_lun->ba_lun_handle;
267266
268267 if (validate_alloc(bali, to_free)) {
269− pr_debug("%s: The AUN %llX is not allocated on lun_id %llX\n",
268+ pr_debug("%s: AUN %llx is not allocated on lun_id=%016llx\n",
270269 __func__, to_free, ba_lun->lun_id);
271270 return -1;
272271 }
273272
274− pr_debug("%s: Received a request to free AU %llX on lun_id %llX, "
275− "free_aun_cnt = %llX\n", __func__, to_free, ba_lun->lun_id,
273+ pr_debug("%s: Received a request to free AU=%llx lun_id=%016llx "
274+ "free_aun_cnt=%llx\n", __func__, to_free, ba_lun->lun_id,
276275 bali->free_aun_cnt);
277276
278277 if (bali->aun_clone_map[to_free] > 0) {
279− pr_debug("%s: AUN %llX on lun_id %llX has been cloned. Clone "
280− "count = %X\n", __func__, to_free, ba_lun->lun_id,
278+ pr_debug("%s: AUN %llx lun_id=%016llx cloned. Clone count=%x\n",
279+ __func__, to_free, ba_lun->lun_id,
281280 bali->aun_clone_map[to_free]);
282281 bali->aun_clone_map[to_free]--;
283282 return 0;
@@ -294,8 +293,8 @@ static int ba_free(struct ba_lun *ba_lun, u64 to_free) · 10 unmodified lines
294293 else if (idx > bali->free_high_idx)
295294 bali->free_high_idx = idx;
296295
297− pr_debug("%s: Successfully freed AU at bit_pos %X, bit map index %X on "
298− "lun_id %llX, free_aun_cnt = %llX\n", __func__, bit_pos, idx,
296+ pr_debug("%s: Successfully freed AU bit_pos=%x bit map index=%x "
297+ "lun_id=%016llx free_aun_cnt=%llx\n", __func__, bit_pos, idx,
299298 ba_lun->lun_id, bali->free_aun_cnt);
300299
301300 return 0;
@@ -313,16 +312,16 @@ static int ba_clone(struct ba_lun *ba_lun, u64 to_clone) · 11 unmodified lines
313312 struct ba_lun_info *bali = ba_lun->ba_lun_handle;
314313
315314 if (validate_alloc(bali, to_clone)) {
316− pr_debug("%s: AUN %llX is not allocated on lun_id %llX\n",
315+ pr_debug("%s: AUN=%llx not allocated on lun_id=%016llx\n",
317316 __func__, to_clone, ba_lun->lun_id);
318317 return -1;
319318 }
320319
321− pr_debug("%s: Received a request to clone AUN %llX on lun_id %llX\n",
320+ pr_debug("%s: Received a request to clone AUN %llx on lun_id=%016llx\n",
322321 __func__, to_clone, ba_lun->lun_id);
323322
324323 if (bali->aun_clone_map[to_clone] == MAX_AUN_CLONE_CNT) {
325− pr_debug("%s: AUN %llX on lun_id %llX hit max clones already\n",
324+ pr_debug("%s: AUN %llx on lun_id=%016llx hit max clones already\n",
326325 __func__, to_clone, ba_lun->lun_id);
327326 return -1;
328327 }
@@ -433,7 +432,7 @@ static int write_same16(struct scsi_device *sdev, · 104 unmodified lines
433432 u64 offset = lba;
434433 int left = nblks;
435434 u32 to = sdev->request_queue->rq_timeout;
436− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
435+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
437436 struct device *dev = &cfg->dev->dev;
438437
439438 cmd_buf = kzalloc(CMD_BUFSIZE, GFP_KERNEL);
@@ -459,7 +458,7 @@ static int write_same16(struct scsi_device *sdev, · 19 unmodified lines
459458 down_read(&cfg->ioctl_rwsem);
460459 rc = check_state(cfg);
461460 if (rc) {
462− dev_err(dev, "%s: Failed state! result=0x08%X\n",
461+ dev_err(dev, "%s: Failed state result=%08x\n",
463462 __func__, result);
464463 rc = -ENODEV;
465464 goto out;
@@ -467,7 +466,7 @@ static int write_same16(struct scsi_device *sdev, · 1 unmodified line
467466
468467 if (result) {
469468 dev_err_ratelimited(dev, "%s: command failed for "
470− "offset %lld result=0x%x\n",
469+ "offset=%lld result=%08x\n",
471470 __func__, offset, result);
472471 rc = -EIO;
473472 goto out;
@@ -480,7 +479,7 @@ out: · 6 unmodified lines
480479 kfree(cmd_buf);
481480 kfree(scsi_cmd);
482481 kfree(sense_buf);
483− pr_debug("%s: returning rc=%d\n", __func__, rc);
482+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
484483 return rc;
485484 }
486485
@@ -508,6 +507,8 @@ static int grow_lxt(struct afu *afu, · 21 unmodified lines
508507 struct sisl_rht_entry *rhte,
509508 u64 *new_size)
510509 {
510+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
511+ struct device *dev = &cfg->dev->dev;
511512 struct sisl_lxt_entry *lxt = NULL, *lxt_old = NULL;
512513 struct llun_info *lli = sdev->hostdata;
513514 struct glun_info *gli = lli->parent;
@@ -527,7 +528,8 @@ static int grow_lxt(struct afu *afu, · 13 unmodified lines
527528 mutex_lock(&blka->mutex);
528529 av_size = ba_space(&blka->ba_lun);
529530 if (unlikely(av_size <= 0)) {
530− pr_debug("%s: ba_space error: av_size %d\n", __func__, av_size);
531+ dev_dbg(dev, "%s: ba_space error av_size=%d\n",
532+ __func__, av_size);
531533 mutex_unlock(&blka->mutex);
532534 rc = -ENOSPC;
533535 goto out;
@@ -568,8 +570,8 @@ static int grow_lxt(struct afu *afu, · 34 unmodified lines
568570 */
569571 aun = ba_alloc(&blka->ba_lun);
570572 if ((aun == -1ULL) || (aun >= blka->nchunk))
571− pr_debug("%s: ba_alloc error: allocated chunk# %llX, "
572− "max %llX\n", __func__, aun, blka->nchunk - 1);
573+ dev_dbg(dev, "%s: ba_alloc error allocated chunk=%llu "
574+ "max=%llu\n", __func__, aun, blka->nchunk - 1);
573575
574576 /* select both ports, use r/w perms from RHT */
575577 lxt[i].rlba_base = ((aun << MC_CHUNK_SHIFT) |
@@ -599,7 +601,7 @@ static int grow_lxt(struct afu *afu, · 23 unmodified lines
599601 kfree(lxt_old);
600602 *new_size = my_new_size;
601603 out:
602− pr_debug("%s: returning rc=%d\n", __func__, rc);
604+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
603605 return rc;
604606 }
605607
@@ -621,6 +623,8 @@ static int shrink_lxt(struct afu *afu, · 15 unmodified lines
621623 struct ctx_info *ctxi,
622624 u64 *new_size)
623625 {
626+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
627+ struct device *dev = &cfg->dev->dev;
624628 struct sisl_lxt_entry *lxt, *lxt_old;
625629 struct llun_info *lli = sdev->hostdata;
626630 struct glun_info *gli = lli->parent;
@@ -706,7 +710,7 @@ static int shrink_lxt(struct afu *afu, · 79 unmodified lines
706710 kfree(lxt_old);
707711 *new_size = my_new_size;
708712 out:
709− pr_debug("%s: returning rc=%d\n", __func__, rc);
713+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
710714 return rc;
711715 }
712716
@@ -728,7 +732,8 @@ int _cxlflash_vlun_resize(struct scsi_device *sdev, · 15 unmodified lines
728732 struct ctx_info *ctxi,
729733 struct dk_cxlflash_resize *resize)
730734 {
731− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
735+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
736+ struct device *dev = &cfg->dev->dev;
732737 struct llun_info *lli = sdev->hostdata;
733738 struct glun_info *gli = lli->parent;
734739 struct afu *afu = cfg->afu;
@@ -751,13 +756,13 @@ int _cxlflash_vlun_resize(struct scsi_device *sdev, · 16 unmodified lines
751756 nsectors = (resize->req_size * CXLFLASH_BLOCK_SIZE) / gli->blk_len;
752757 new_size = DIV_ROUND_UP(nsectors, MC_CHUNK_SIZE);
753758
754− pr_debug("%s: ctxid=%llu rhndl=0x%llx, req_size=0x%llx,"
755− "new_size=%llx\n", __func__, ctxid, resize->rsrc_handle,
756− resize->req_size, new_size);
759+ dev_dbg(dev, "%s: ctxid=%llu rhndl=%llu req_size=%llu new_size=%llu\n",
760+ __func__, ctxid, resize->rsrc_handle, resize->req_size,
761+ new_size);
757762
758763 if (unlikely(gli->mode != MODE_VIRTUAL)) {
759− pr_debug("%s: LUN mode does not support resize! (%d)\n",
760− __func__, gli->mode);
764+ dev_dbg(dev, "%s: LUN mode does not support resize mode=%d\n",
765+ __func__, gli->mode);
761766 rc = -EINVAL;
762767 goto out;
763768
@@ -766,7 +771,8 @@ int _cxlflash_vlun_resize(struct scsi_device *sdev, · 2 unmodified lines
766771 if (!ctxi) {
767772 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
768773 if (unlikely(!ctxi)) {
769− pr_debug("%s: Bad context! (%llu)\n", __func__, ctxid);
774+ dev_dbg(dev, "%s: Bad context ctxid=%llu\n",
775+ __func__, ctxid);
770776 rc = -EINVAL;
771777 goto out;
772778 }
@@ -776,7 +782,8 @@ int _cxlflash_vlun_resize(struct scsi_device *sdev, · 3 unmodified lines
776782
777783 rhte = get_rhte(ctxi, rhndl, lli);
778784 if (unlikely(!rhte)) {
779− pr_debug("%s: Bad resource handle! (%u)\n", __func__, rhndl);
785+ dev_dbg(dev, "%s: Bad resource handle rhndl=%u\n",
786+ __func__, rhndl);
780787 rc = -EINVAL;
781788 goto out;
782789 }
@@ -794,8 +801,8 @@ int _cxlflash_vlun_resize(struct scsi_device *sdev, · 11 unmodified lines
794801 out:
795802 if (put_ctx)
796803 put_context(ctxi);
797− pr_debug("%s: resized to %lld returning rc=%d\n",
798− __func__, resize->last_lba, rc);
804+ dev_dbg(dev, "%s: resized to %llu returning rc=%d\n",
805+ __func__, resize->last_lba, rc);
799806 return rc;
800807 }
801808
@@ -815,6 +822,7 @@ void cxlflash_restore_luntable(struct cxlflash_cfg *cfg) · 13 unmodified lines
815822 u32 chan;
816823 u32 lind;
817824 struct afu *afu = cfg->afu;
825+ struct device *dev = &cfg->dev->dev;
818826 struct sisl_global_map __iomem *agm = &afu->afu_map->global;
819827
820828 mutex_lock(&global.mutex);
@@ -828,15 +836,15 @@ void cxlflash_restore_luntable(struct cxlflash_cfg *cfg) · 7 unmodified lines
828836 if (lli->port_sel == BOTH_PORTS) {
829837 writeq_be(lli->lun_id[0], &agm->fc_port[0][lind]);
830838 writeq_be(lli->lun_id[1], &agm->fc_port[1][lind]);
831− pr_debug("%s: Virtual LUN on slot %d id0=%llx, "
832− "id1=%llx\n", __func__, lind,
833− lli->lun_id[0], lli->lun_id[1]);
839+ dev_dbg(dev, "%s: Virtual LUN on slot %d id0=%llx "
840+ "id1=%llx\n", __func__, lind,
841+ lli->lun_id[0], lli->lun_id[1]);
834842 } else {
835843 chan = PORT2CHAN(lli->port_sel);
836844 writeq_be(lli->lun_id[chan], &agm->fc_port[chan][lind]);
837− pr_debug("%s: Virtual LUN on slot %d chan=%d, "
838− "id=%llx\n", __func__, lind, chan,
839− lli->lun_id[chan]);
845+ dev_dbg(dev, "%s: Virtual LUN on slot %d chan=%d "
846+ "id=%llx\n", __func__, lind, chan,
847+ lli->lun_id[chan]);
840848 }
841849 }
842850
@@ -860,6 +868,7 @@ static int init_luntable(struct cxlflash_cfg *cfg, struct llun_info *lli) · 17 unmodified lines
860868 u32 lind;
861869 int rc = 0;
862870 struct afu *afu = cfg->afu;
871+ struct device *dev = &cfg->dev->dev;
863872 struct sisl_global_map __iomem *agm = &afu->afu_map->global;
864873
865874 mutex_lock(&global.mutex);
@@ -882,8 +891,8 @@ static int init_luntable(struct cxlflash_cfg *cfg, struct llun_info *lli) · 16 unmodified lines
882891 writeq_be(lli->lun_id[0], &agm->fc_port[0][lind]);
883892 writeq_be(lli->lun_id[1], &agm->fc_port[1][lind]);
884893 cfg->promote_lun_index++;
885− pr_debug("%s: Virtual LUN on slot %d id0=%llx, id1=%llx\n",
886− __func__, lind, lli->lun_id[0], lli->lun_id[1]);
894+ dev_dbg(dev, "%s: Virtual LUN on slot %d id0=%llx id1=%llx\n",
895+ __func__, lind, lli->lun_id[0], lli->lun_id[1]);
887896 } else {
888897 /*
889898 * If this LUN is visible only from one port, we will put
@@ -898,14 +907,14 @@ static int init_luntable(struct cxlflash_cfg *cfg, struct llun_info *lli) · 8 unmodified lines
898907 lind = lli->lun_index = cfg->last_lun_index[chan];
899908 writeq_be(lli->lun_id[chan], &agm->fc_port[chan][lind]);
900909 cfg->last_lun_index[chan]--;
901− pr_debug("%s: Virtual LUN on slot %d chan=%d, id=%llx\n",
902− __func__, lind, chan, lli->lun_id[chan]);
910+ dev_dbg(dev, "%s: Virtual LUN on slot %d chan=%d id=%llx\n",
911+ __func__, lind, chan, lli->lun_id[chan]);
903912 }
904913
905914 lli->in_table = true;
906915 out:
907916 mutex_unlock(&global.mutex);
908− pr_debug("%s: returning rc=%d\n", __func__, rc);
917+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
909918 return rc;
910919 }
911920
@@ -923,7 +932,7 @@ out: · 11 unmodified lines
923932 */
924933 int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg)
925934 {
926− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
935+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
927936 struct device *dev = &cfg->dev->dev;
928937 struct llun_info *lli = sdev->hostdata;
929938 struct glun_info *gli = lli->parent;
@@ -942,14 +951,14 @@ int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg) · 12 unmodified lines
942951 struct ctx_info *ctxi = NULL;
943952 struct sisl_rht_entry *rhte = NULL;
944953
945− pr_debug("%s: ctxid=%llu ls=0x%llx\n", __func__, ctxid, lun_size);
954+ dev_dbg(dev, "%s: ctxid=%llu ls=%llu\n", __func__, ctxid, lun_size);
946955
947956 /* Setup the LUNs block allocator on first call */
948957 mutex_lock(&gli->mutex);
949958 if (gli->mode == MODE_NONE) {
950959 rc = init_vlun(lli);
951960 if (rc) {
952− dev_err(dev, "%s: call to init_vlun failed rc=%d!\n",
961+ dev_err(dev, "%s: init_vlun failed rc=%d\n",
953962 __func__, rc);
954963 rc = -ENOMEM;
955964 goto err0;
@@ -958,29 +967,28 @@ int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg) · 2 unmodified lines
958967
959968 rc = cxlflash_lun_attach(gli, MODE_VIRTUAL, true);
960969 if (unlikely(rc)) {
961− dev_err(dev, "%s: Failed to attach to LUN! (VIRTUAL)\n",
962− __func__);
970+ dev_err(dev, "%s: Failed attach to LUN (VIRTUAL)\n", __func__);
963971 goto err0;
964972 }
965973 mutex_unlock(&gli->mutex);
966974
967975 rc = init_luntable(cfg, lli);
968976 if (rc) {
969− dev_err(dev, "%s: call to init_luntable failed rc=%d!\n",
970− __func__, rc);
977+ dev_err(dev, "%s: init_luntable failed rc=%d\n", __func__, rc);
971978 goto err1;
972979 }
973980
974981 ctxi = get_context(cfg, rctxid, lli, 0);
975982 if (unlikely(!ctxi)) {
976− dev_err(dev, "%s: Bad context! (%llu)\n", __func__, ctxid);
983+ dev_err(dev, "%s: Bad context ctxid=%llu\n", __func__, ctxid);
977984 rc = -EINVAL;
978985 goto err1;
979986 }
980987
981988 rhte = rhte_checkout(ctxi, lli);
982989 if (unlikely(!rhte)) {
983− dev_err(dev, "%s: too many opens for this context\n", __func__);
990+ dev_err(dev, "%s: too many opens ctxid=%llu\n",
991+ __func__, ctxid);
984992 rc = -EMFILE; /* too many opens */
985993 goto err1;
986994 }
@@ -996,7 +1004,7 @@ int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg) · 9 unmodified lines
9961004 resize.rsrc_handle = rsrc_handle;
9971005 rc = _cxlflash_vlun_resize(sdev, ctxi, &resize);
9981006 if (rc) {
999− dev_err(dev, "%s: resize failed rc %d\n", __func__, rc);
1007+ dev_err(dev, "%s: resize failed rc=%d\n", __func__, rc);
10001008 goto err2;
10011009 }
10021010 last_lba = resize.last_lba;
@@ -1013,8 +1021,8 @@ int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg) · 10 unmodified lines
10131021 out:
10141022 if (likely(ctxi))
10151023 put_context(ctxi);
1016− pr_debug("%s: returning handle 0x%llx rc=%d llba %lld\n",
1017− __func__, rsrc_handle, rc, last_lba);
1024+ dev_dbg(dev, "%s: returning handle=%llu rc=%d llba=%llu\n",
1025+ __func__, rsrc_handle, rc, last_lba);
10181026 return rc;
10191027
10201028 err2:
@@ -1047,6 +1055,8 @@ static int clone_lxt(struct afu *afu, · 26 unmodified lines
10471055 struct sisl_rht_entry *rhte,
10481056 struct sisl_rht_entry *rhte_src)
10491057 {
1058+ struct cxlflash_cfg *cfg = afu->parent;
1059+ struct device *dev = &cfg->dev->dev;
10501060 struct sisl_lxt_entry *lxt;
10511061 u32 ngrps;
10521062 u64 aun; /* chunk# allocated by block allocator */
@@ -1101,7 +1111,7 @@ static int clone_lxt(struct afu *afu, · 48 unmodified lines
11011111
11021112 cxlflash_afu_sync(afu, ctxid, rhndl, AFU_LW_SYNC);
11031113
1104− pr_debug("%s: returning\n", __func__);
1114+ dev_dbg(dev, "%s: returning\n", __func__);
11051115 return 0;
11061116 }
11071117
@@ -1120,7 +1130,8 @@ static int clone_lxt(struct afu *afu, · 12 unmodified lines
11201130 int cxlflash_disk_clone(struct scsi_device *sdev,
11211131 struct dk_cxlflash_clone *clone)
11221132 {
1123− struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)sdev->host->hostdata;
1133+ struct cxlflash_cfg *cfg = shost_priv(sdev->host);
1134+ struct device *dev = &cfg->dev->dev;
11241135 struct llun_info *lli = sdev->hostdata;
11251136 struct glun_info *gli = lli->parent;
11261137 struct blka *blka = &gli->blka;
@@ -1140,8 +1151,8 @@ int cxlflash_disk_clone(struct scsi_device *sdev, · 13 unmodified lines
11401151 bool found;
11411152 LIST_HEAD(sidecar);
11421153
1143− pr_debug("%s: ctxid_src=%llu ctxid_dst=%llu\n",
1144− __func__, ctxid_src, ctxid_dst);
1154+ dev_dbg(dev, "%s: ctxid_src=%llu ctxid_dst=%llu\n",
1155+ __func__, ctxid_src, ctxid_dst);
11451156
11461157 /* Do not clone yourself */
11471158 if (unlikely(rctxid_src == rctxid_dst)) {
@@ -1151,16 +1162,16 @@ int cxlflash_disk_clone(struct scsi_device *sdev, · 3 unmodified lines
11511162
11521163 if (unlikely(gli->mode != MODE_VIRTUAL)) {
11531164 rc = -EINVAL;
1154− pr_debug("%s: Clone not supported on physical LUNs! (%d)\n",
1155− __func__, gli->mode);
1165+ dev_dbg(dev, "%s: Only supported on virtual LUNs mode=%u\n",
1166+ __func__, gli->mode);
11561167 goto out;
11571168 }
11581169
11591170 ctxi_src = get_context(cfg, rctxid_src, lli, CTX_CTRL_CLONE);
11601171 ctxi_dst = get_context(cfg, rctxid_dst, lli, 0);
11611172 if (unlikely(!ctxi_src || !ctxi_dst)) {
1162− pr_debug("%s: Bad context! (%llu,%llu)\n", __func__,
1163− ctxid_src, ctxid_dst);
1173+ dev_dbg(dev, "%s: Bad context ctxid_src=%llu ctxid_dst=%llu\n",
1174+ __func__, ctxid_src, ctxid_dst);
11641175 rc = -EINVAL;
11651176 goto out;
11661177 }
@@ -1185,8 +1196,8 @@ int cxlflash_disk_clone(struct scsi_device *sdev, · 18 unmodified lines
11851196 lun_access_dst = kzalloc(sizeof(*lun_access_dst),
11861197 GFP_KERNEL);
11871198 if (unlikely(!lun_access_dst)) {
1188− pr_err("%s: Unable to allocate lun_access!\n",
1189− __func__);
1199+ dev_err(dev, "%s: lun_access allocation fail\n",
1200+ __func__);
11901201 rc = -ENOMEM;
11911202 goto out;
11921203 }
@@ -1197,7 +1208,7 @@ int cxlflash_disk_clone(struct scsi_device *sdev, · 4 unmodified lines
11971208 }
11981209
11991210 if (unlikely(!ctxi_src->rht_out)) {
1200− pr_debug("%s: Nothing to clone!\n", __func__);
1211+ dev_dbg(dev, "%s: Nothing to clone\n", __func__);
12011212 goto out_success;
12021213 }
12031214
@@ -1256,7 +1267,7 @@ out: · 52 unmodified lines
12561267 put_context(ctxi_src);
12571268 if (ctxi_dst)
12581269 put_context(ctxi_dst);
1259− pr_debug("%s: returning rc=%d\n", __func__, rc);
1270+ dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
12601271 return rc;
12611272
12621273 err:
drivers/scsi/dpt_i2o.c+2−6
@@ -2768,16 +2768,12 @@ static int adpt_i2o_activate_hba(adpt_hba* pHba) · 2767 unmodified lines
27682768
27692769 static int adpt_i2o_online_hba(adpt_hba* pHba)
27702770 {
2771− if (adpt_i2o_systab_send(pHba) < 0) {
2772− adpt_i2o_delete_hba(pHba);
2771+ if (adpt_i2o_systab_send(pHba) < 0)
27732772 return -1;
2774− }
27752773 /* In READY state */
27762774
2777− if (adpt_i2o_enable_hba(pHba) < 0) {
2778− adpt_i2o_delete_hba(pHba);
2775+ if (adpt_i2o_enable_hba(pHba) < 0)
27792776 return -1;
2780− }
27812777
27822778 /* In OPERATIONAL state */
27832779 return 0;
drivers/scsi/esas2r/esas2r_init.c+1−1
@@ -237,7 +237,7 @@ static void esas2r_claim_interrupts(struct esas2r_adapter *a) · 236 unmodified lines
237237 flags |= IRQF_SHARED;
238238
239239 esas2r_log(ESAS2R_LOG_INFO,
240− "esas2r_claim_interrupts irq=%d (%p, %s, %x)",
240+ "esas2r_claim_interrupts irq=%d (%p, %s, %lx)",
241241 a->pcid->irq, a, a->name, flags);
242242
243243 if (request_irq(a->pcid->irq,
drivers/scsi/esas2r/esas2r_ioctl.c+1−1
@@ -1301,7 +1301,7 @@ int esas2r_ioctl_handler(void *hostdata, int cmd, void __user *arg) · 1300 unmodified lines
13011301 ioctl = kzalloc(sizeof(struct atto_express_ioctl), GFP_KERNEL);
13021302 if (ioctl == NULL) {
13031303 esas2r_log(ESAS2R_LOG_WARN,
1304− "ioctl_handler kzalloc failed for %d bytes",
1304+ "ioctl_handler kzalloc failed for %zu bytes",
13051305 sizeof(struct atto_express_ioctl));
13061306 return -ENOMEM;
13071307 }
drivers/scsi/esas2r/esas2r_log.h+2−2
@@ -61,8 +61,8 @@ enum { · 60 unmodified lines
6161 #endif
6262 };
6363
64−int esas2r_log(const long level, const char *format, ...);
65−int esas2r_log_dev(const long level,
64+__printf(2, 3) int esas2r_log(const long level, const char *format, ...);
65+__printf(3, 4) int esas2r_log_dev(const long level,
6666 const struct device *dev,
6767 const char *format,
6868 ...);
drivers/scsi/esas2r/esas2r_main.c+2−2
@@ -198,7 +198,7 @@ static ssize_t write_hw(struct file *file, struct kobject *kobj, · 197 unmodified lines
198198 GFP_KERNEL);
199199 if (a->local_atto_ioctl == NULL) {
200200 esas2r_log(ESAS2R_LOG_WARN,
201− "write_hw kzalloc failed for %d bytes",
201+ "write_hw kzalloc failed for %zu bytes",
202202 sizeof(struct atto_ioctl));
203203 return -ENOMEM;
204204 }
@@ -1186,7 +1186,7 @@ retry: · 981 unmodified lines
11861186 } else {
11871187 esas2r_log(ESAS2R_LOG_CRIT,
11881188 "unable to allocate a request for a "
1189− "device reset (%d:%d)!",
1189+ "device reset (%d:%llu)!",
11901190 cmd->device->id,
11911191 cmd->device->lun);
11921192 }
drivers/scsi/fcoe/fcoe.c+1−0
@@ -277,6 +277,7 @@ static struct scsi_host_template fcoe_shost_template = { · 276 unmodified lines
277277 .name = "FCoE Driver",
278278 .proc_name = FCOE_NAME,
279279 .queuecommand = fc_queuecommand,
280+ .eh_timed_out = fc_eh_timed_out,
280281 .eh_abort_handler = fc_eh_abort,
281282 .eh_device_reset_handler = fc_eh_device_reset,
282283 .eh_host_reset_handler = fc_eh_host_reset,
drivers/scsi/fnic/fnic_main.c+1−0
@@ -106,6 +106,7 @@ static struct scsi_host_template fnic_host_template = { · 105 unmodified lines
106106 .module = THIS_MODULE,
107107 .name = DRV_NAME,
108108 .queuecommand = fnic_queuecommand,
109+ .eh_timed_out = fc_eh_timed_out,
109110 .eh_abort_handler = fnic_abort_cmd,
110111 .eh_device_reset_handler = fnic_device_reset,
111112 .eh_host_reset_handler = fnic_host_reset,
drivers/scsi/g_NCR5380.c+43−2
@@ -26,14 +26,55 @@ · 25 unmodified lines
2626 #include <linux/blkdev.h>
2727 #include <linux/module.h>
2828 #include <scsi/scsi_host.h>
29−#include "g_NCR5380.h"
30−#include "NCR5380.h"
3129 #include <linux/init.h>
3230 #include <linux/ioport.h>
3331 #include <linux/isa.h>
3432 #include <linux/pnp.h>
3533 #include <linux/interrupt.h>
3634
35+/* Definitions for the core NCR5380 driver. */
36+
37+#define NCR5380_read(reg) \
38+ ioread8(hostdata->io + hostdata->offset + (reg))
39+#define NCR5380_write(reg, value) \
40+ iowrite8(value, hostdata->io + hostdata->offset + (reg))
41+
42+#define NCR5380_implementation_fields \
43+ int offset; \
44+ int c400_ctl_status; \
45+ int c400_blk_cnt; \
46+ int c400_host_buf; \
47+ int io_width
48+
49+#define NCR5380_dma_xfer_len generic_NCR5380_dma_xfer_len
50+#define NCR5380_dma_recv_setup generic_NCR5380_pread
51+#define NCR5380_dma_send_setup generic_NCR5380_pwrite
52+#define NCR5380_dma_residual NCR5380_dma_residual_none
53+
54+#define NCR5380_intr generic_NCR5380_intr
55+#define NCR5380_queue_command generic_NCR5380_queue_command
56+#define NCR5380_abort generic_NCR5380_abort
57+#define NCR5380_bus_reset generic_NCR5380_bus_reset
58+#define NCR5380_info generic_NCR5380_info
59+
60+#define NCR5380_io_delay(x) udelay(x)
61+
62+#include "NCR5380.h"
63+
64+#define DRV_MODULE_NAME "g_NCR5380"
65+
66+#define NCR53C400_mem_base 0x3880
67+#define NCR53C400_host_buffer 0x3900
68+#define NCR53C400_region_size 0x3a00
69+
70+#define BOARD_NCR5380 0
71+#define BOARD_NCR53C400 1
72+#define BOARD_NCR53C400A 2
73+#define BOARD_DTC3181E 3
74+#define BOARD_HP_C2502 4
75+
76+#define IRQ_AUTO 254
77+
3778 #define MAX_CARDS 8
3879
3980 /* old-style parameters for compatibility */
drivers/scsi/g_NCR5380.h+0−56
@@ -1,56 +0,0 @@
1−/*
2− * Generic Generic NCR5380 driver defines
3− *
4− * Copyright 1993, Drew Eckhardt
5− * Visionary Computing
6− * (Unix and Linux consulting and custom programming)
7− * drew@colorado.edu
8− * +1 (303) 440-4894
9− *
10− * NCR53C400 extensions (c) 1994,1995,1996, Kevin Lentin
11− * K.Lentin@cs.monash.edu.au
12− */
13−
14−#ifndef GENERIC_NCR5380_H
15−#define GENERIC_NCR5380_H
16−
17−#define DRV_MODULE_NAME "g_NCR5380"
18−
19−#define NCR5380_read(reg) \
20− ioread8(hostdata->io + hostdata->offset + (reg))
21−#define NCR5380_write(reg, value) \
22− iowrite8(value, hostdata->io + hostdata->offset + (reg))
23−
24−#define NCR5380_implementation_fields \
25− int offset; \
26− int c400_ctl_status; \
27− int c400_blk_cnt; \
28− int c400_host_buf; \
29− int io_width;
30−
31−#define NCR53C400_mem_base 0x3880
32−#define NCR53C400_host_buffer 0x3900
33−#define NCR53C400_region_size 0x3a00
34−
35−#define NCR5380_dma_xfer_len generic_NCR5380_dma_xfer_len
36−#define NCR5380_dma_recv_setup generic_NCR5380_pread
37−#define NCR5380_dma_send_setup generic_NCR5380_pwrite
38−#define NCR5380_dma_residual NCR5380_dma_residual_none
39−
40−#define NCR5380_intr generic_NCR5380_intr
41−#define NCR5380_queue_command generic_NCR5380_queue_command
42−#define NCR5380_abort generic_NCR5380_abort
43−#define NCR5380_bus_reset generic_NCR5380_bus_reset
44−#define NCR5380_info generic_NCR5380_info
45−
46−#define NCR5380_io_delay(x) udelay(x)
47−
48−#define BOARD_NCR5380 0
49−#define BOARD_NCR53C400 1
50−#define BOARD_NCR53C400A 2
51−#define BOARD_DTC3181E 3
52−#define BOARD_HP_C2502 4
53−
54−#define IRQ_AUTO 254
55−
56−#endif /* GENERIC_NCR5380_H */
drivers/scsi/hisi_sas/hisi_sas.h+1−0
@@ -95,6 +95,7 @@ struct hisi_sas_port { · 94 unmodified lines
9595
9696 struct hisi_sas_cq {
9797 struct hisi_hba *hisi_hba;
98+ struct tasklet_struct tasklet;
9899 int rd_point;
99100 int id;
100101 };
drivers/scsi/hisi_sas/hisi_sas_main.c+13−10
@@ -71,6 +71,8 @@ void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task, · 70 unmodified lines
7171 struct hisi_sas_slot *slot)
7272 {
7373 struct device *dev = &hisi_hba->pdev->dev;
74+ struct domain_device *device = task->dev;
75+ struct hisi_sas_device *sas_dev = device->lldd_dev;
7476
7577 if (!slot->task)
7678 return;
@@ -97,6 +99,8 @@ void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task, · 20 unmodified lines
9799 slot->task = NULL;
98100 slot->port = NULL;
99101 hisi_sas_slot_index_free(hisi_hba, slot->idx);
102+ if (sas_dev)
103+ atomic64_dec(&sas_dev->running_req);
100104 /* slot memory is fully zeroed when it is reused */
101105 }
102106 EXPORT_SYMBOL_GPL(hisi_sas_slot_task_free);
@@ -141,11 +145,10 @@ static void hisi_sas_slot_abort(struct work_struct *work) · 38 unmodified lines
141145 struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev);
142146 struct scsi_cmnd *cmnd = task->uldd_task;
143147 struct hisi_sas_tmf_task tmf_task;
144− struct domain_device *device = task->dev;
145− struct hisi_sas_device *sas_dev = device->lldd_dev;
146148 struct scsi_lun lun;
147149 struct device *dev = &hisi_hba->pdev->dev;
148150 int tag = abort_slot->idx;
151+ unsigned long flags;
149152
150153 if (!(task->task_proto & SAS_PROTOCOL_SSP)) {
151154 dev_err(dev, "cannot abort slot for non-ssp task\n");
@@ -159,11 +162,11 @@ static void hisi_sas_slot_abort(struct work_struct *work) · 7 unmodified lines
159162 hisi_sas_debug_issue_ssp_tmf(task->dev, lun.scsi_lun, &tmf_task);
160163 out:
161164 /* Do cleanup for this task */
165+ spin_lock_irqsave(&hisi_hba->lock, flags);
162166 hisi_sas_slot_task_free(hisi_hba, task, abort_slot);
167+ spin_unlock_irqrestore(&hisi_hba->lock, flags);
163168 if (task->task_done)
164169 task->task_done(task);
165− if (sas_dev)
166− atomic64_dec(&sas_dev->running_req);
167170 }
168171
169172 static int hisi_sas_task_prep(struct sas_task *task, struct hisi_hba *hisi_hba,
@@ -1118,7 +1121,7 @@ hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba, · 948 unmodified lines
11181121 }
11191122
11201123 exit:
1121− dev_info(dev, "internal task abort: task to dev %016llx task=%p "
1124+ dev_dbg(dev, "internal task abort: task to dev %016llx task=%p "
11221125 "resp: 0x%x sts 0x%x\n",
11231126 SAS_ADDR(device->sas_addr),
11241127 task,
@@ -1450,7 +1453,7 @@ static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev, · 325 unmodified lines
14501453
14511454 refclk = devm_clk_get(&pdev->dev, NULL);
14521455 if (IS_ERR(refclk))
1453− dev_info(dev, "no ref clk property\n");
1456+ dev_dbg(dev, "no ref clk property\n");
14541457 else
14551458 hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000;
14561459
@@ -1549,10 +1552,6 @@ int hisi_sas_probe(struct platform_device *pdev, · 92 unmodified lines
15491552
15501553 hisi_sas_init_add(hisi_hba);
15511554
1552− rc = hisi_hba->hw->hw_init(hisi_hba);
1553− if (rc)
1554− goto err_out_ha;
1555−
15561555 rc = scsi_add_host(shost, &pdev->dev);
15571556 if (rc)
15581557 goto err_out_ha;
@@ -1561,6 +1560,10 @@ int hisi_sas_probe(struct platform_device *pdev, · 2 unmodified lines
15611560 if (rc)
15621561 goto err_out_register_ha;
15631562
1563+ rc = hisi_hba->hw->hw_init(hisi_hba);
1564+ if (rc)
1565+ goto err_out_register_ha;
1566+
15641567 scsi_scan_host(shost);
15651568
15661569 return 0;
drivers/scsi/hisi_sas/hisi_sas_v1_hw.c+2−0
@@ -1596,6 +1596,7 @@ static irqreturn_t cq_interrupt_v1_hw(int irq, void *p) · 1595 unmodified lines
15961596 hisi_hba->complete_hdr[queue];
15971597 u32 irq_value, rd_point = cq->rd_point, wr_point;
15981598
1599+ spin_lock(&hisi_hba->lock);
15991600 irq_value = hisi_sas_read32(hisi_hba, OQ_INT_SRC);
16001601
16011602 hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
@@ -1628,6 +1629,7 @@ static irqreturn_t cq_interrupt_v1_hw(int irq, void *p) · 26 unmodified lines
16281629 /* update rd_point */
16291630 cq->rd_point = rd_point;
16301631 hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point);
1632+ spin_unlock(&hisi_hba->lock);
16311633
16321634 return IRQ_HANDLED;
16331635 }
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c+116−19
@@ -207,6 +207,8 @@ · 206 unmodified lines
207207 #define TXID_AUTO (PORT_BASE + 0xb8)
208208 #define TXID_AUTO_CT3_OFF 1
209209 #define TXID_AUTO_CT3_MSK (0x1 << TXID_AUTO_CT3_OFF)
210+#define TX_HARDRST_OFF 2
211+#define TX_HARDRST_MSK (0x1 << TX_HARDRST_OFF)
210212 #define RX_IDAF_DWORD0 (PORT_BASE + 0xc4)
211213 #define RX_IDAF_DWORD1 (PORT_BASE + 0xc8)
212214 #define RX_IDAF_DWORD2 (PORT_BASE + 0xcc)
@@ -215,6 +217,7 @@ · 2 unmodified lines
215217 #define RX_IDAF_DWORD5 (PORT_BASE + 0xd8)
216218 #define RX_IDAF_DWORD6 (PORT_BASE + 0xdc)
217219 #define RXOP_CHECK_CFG_H (PORT_BASE + 0xfc)
220+#define CON_CONTROL (PORT_BASE + 0x118)
218221 #define DONE_RECEIVED_TIME (PORT_BASE + 0x11c)
219222 #define CHL_INT0 (PORT_BASE + 0x1b4)
220223 #define CHL_INT0_HOTPLUG_TOUT_OFF 0
@@ -333,6 +336,11 @@ · 112 unmodified lines
333336 #define ITCT_HDR_MCR_MSK (0xf << ITCT_HDR_MCR_OFF)
334337 #define ITCT_HDR_VLN_OFF 9
335338 #define ITCT_HDR_VLN_MSK (0xf << ITCT_HDR_VLN_OFF)
339+#define ITCT_HDR_SMP_TIMEOUT_OFF 16
340+#define ITCT_HDR_SMP_TIMEOUT_8US 1
341+#define ITCT_HDR_SMP_TIMEOUT (ITCT_HDR_SMP_TIMEOUT_8US * \
342+ 250) /* 2ms */
343+#define ITCT_HDR_AWT_CONTINUE_OFF 25
336344 #define ITCT_HDR_PORT_ID_OFF 28
337345 #define ITCT_HDR_PORT_ID_MSK (0xf << ITCT_HDR_PORT_ID_OFF)
338346 /* qw2 */
@@ -526,6 +534,8 @@ enum { · 187 unmodified lines
526534 #define SATA_PROTOCOL_FPDMA 0x8
527535 #define SATA_PROTOCOL_ATAPI 0x10
528536
537+static void hisi_sas_link_timeout_disable_link(unsigned long data);
538+
529539 static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off)
530540 {
531541 void __iomem *regs = hisi_hba->regs + off;
@@ -693,6 +703,8 @@ static void setup_itct_v2_hw(struct hisi_hba *hisi_hba, · 161 unmodified lines
693703 qw0 |= ((1 << ITCT_HDR_VALID_OFF) |
694704 (device->linkrate << ITCT_HDR_MCR_OFF) |
695705 (1 << ITCT_HDR_VLN_OFF) |
706+ (ITCT_HDR_SMP_TIMEOUT << ITCT_HDR_SMP_TIMEOUT_OFF) |
707+ (1 << ITCT_HDR_AWT_CONTINUE_OFF) |
696708 (port->id << ITCT_HDR_PORT_ID_OFF));
697709 itct->qw0 = cpu_to_le64(qw0);
698710
@@ -702,7 +714,7 @@ static void setup_itct_v2_hw(struct hisi_hba *hisi_hba, · 3 unmodified lines
702714
703715 /* qw2 */
704716 if (!dev_is_sata(device))
705− itct->qw2 = cpu_to_le64((500ULL << ITCT_HDR_INLT_OFF) |
717+ itct->qw2 = cpu_to_le64((5000ULL << ITCT_HDR_INLT_OFF) |
706718 (0x1ULL << ITCT_HDR_BITLT_OFF) |
707719 (0x32ULL << ITCT_HDR_MCTLT_OFF) |
708720 (0x1ULL << ITCT_HDR_RTOLT_OFF));
@@ -711,7 +723,7 @@ static void setup_itct_v2_hw(struct hisi_hba *hisi_hba, · 2 unmodified lines
711723 static void free_device_v2_hw(struct hisi_hba *hisi_hba,
712724 struct hisi_sas_device *sas_dev)
713725 {
714− u64 qw0, dev_id = sas_dev->device_id;
726+ u64 dev_id = sas_dev->device_id;
715727 struct device *dev = &hisi_hba->pdev->dev;
716728 struct hisi_sas_itct *itct = &hisi_hba->itct[dev_id];
717729 u32 reg_val = hisi_sas_read32(hisi_hba, ENT_INT_SRC3);
@@ -735,8 +747,7 @@ static void free_device_v2_hw(struct hisi_hba *hisi_hba, · 17 unmodified lines
735747 dev_dbg(dev, "got clear ITCT done interrupt\n");
736748
737749 /* invalid the itct state*/
738− qw0 = cpu_to_le64(itct->qw0);
739− qw0 &= ~(1 << ITCT_HDR_VALID_OFF);
750+ memset(itct, 0, sizeof(struct hisi_sas_itct));
740751 hisi_sas_write32(hisi_hba, ENT_INT_SRC3,
741752 ENT_INT_SRC3_ITC_INT_MSK);
742753
@@ -978,6 +989,50 @@ static void init_reg_v2_hw(struct hisi_hba *hisi_hba) · 235 unmodified lines
978989 upper_32_bits(hisi_hba->initial_fis_dma));
979990 }
980991
992+static void hisi_sas_link_timeout_enable_link(unsigned long data)
993+{
994+ struct hisi_hba *hisi_hba = (struct hisi_hba *)data;
995+ int i, reg_val;
996+
997+ for (i = 0; i < hisi_hba->n_phy; i++) {
998+ reg_val = hisi_sas_phy_read32(hisi_hba, i, CON_CONTROL);
999+ if (!(reg_val & BIT(0))) {
1000+ hisi_sas_phy_write32(hisi_hba, i,
1001+ CON_CONTROL, 0x7);
1002+ break;
1003+ }
1004+ }
1005+
1006+ hisi_hba->timer.function = hisi_sas_link_timeout_disable_link;
1007+ mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(900));
1008+}
1009+
1010+static void hisi_sas_link_timeout_disable_link(unsigned long data)
1011+{
1012+ struct hisi_hba *hisi_hba = (struct hisi_hba *)data;
1013+ int i, reg_val;
1014+
1015+ reg_val = hisi_sas_read32(hisi_hba, PHY_STATE);
1016+ for (i = 0; i < hisi_hba->n_phy && reg_val; i++) {
1017+ if (reg_val & BIT(i)) {
1018+ hisi_sas_phy_write32(hisi_hba, i,
1019+ CON_CONTROL, 0x6);
1020+ break;
1021+ }
1022+ }
1023+
1024+ hisi_hba->timer.function = hisi_sas_link_timeout_enable_link;
1025+ mod_timer(&hisi_hba->timer, jiffies + msecs_to_jiffies(100));
1026+}
1027+
1028+static void set_link_timer_quirk(struct hisi_hba *hisi_hba)
1029+{
1030+ hisi_hba->timer.data = (unsigned long)hisi_hba;
1031+ hisi_hba->timer.function = hisi_sas_link_timeout_disable_link;
1032+ hisi_hba->timer.expires = jiffies + msecs_to_jiffies(1000);
1033+ add_timer(&hisi_hba->timer);
1034+}
1035+
9811036 static int hw_init_v2_hw(struct hisi_hba *hisi_hba)
9821037 {
9831038 struct device *dev = &hisi_hba->pdev->dev;
@@ -1025,14 +1080,21 @@ static void stop_phy_v2_hw(struct hisi_hba *hisi_hba, int phy_no) · 41 unmodified lines
10251080
10261081 static void phy_hard_reset_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
10271082 {
1083+ struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
1084+ u32 txid_auto;
1085+
10281086 stop_phy_v2_hw(hisi_hba, phy_no);
1087+ if (phy->identify.device_type == SAS_END_DEVICE) {
1088+ txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
1089+ hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
1090+ txid_auto | TX_HARDRST_MSK);
1091+ }
10291092 msleep(100);
10301093 start_phy_v2_hw(hisi_hba, phy_no);
10311094 }
10321095
1033−static void start_phys_v2_hw(unsigned long data)
1096+static void start_phys_v2_hw(struct hisi_hba *hisi_hba)
10341097 {
1035− struct hisi_hba *hisi_hba = (struct hisi_hba *)data;
10361098 int i;
10371099
10381100 for (i = 0; i < hisi_hba->n_phy; i++)
@@ -1041,10 +1103,7 @@ static void start_phys_v2_hw(unsigned long data) · 2 unmodified lines
10411103
10421104 static void phys_init_v2_hw(struct hisi_hba *hisi_hba)
10431105 {
1044− struct timer_list *timer = &hisi_hba->timer;
1045−
1046− setup_timer(timer, start_phys_v2_hw, (unsigned long)hisi_hba);
1047− mod_timer(timer, jiffies + HZ);
1106+ start_phys_v2_hw(hisi_hba);
10481107 }
10491108
10501109 static void sl_notify_v2_hw(struct hisi_hba *hisi_hba, int phy_no)
@@ -1771,8 +1830,6 @@ slot_complete_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_slot *slot, · 720 unmodified lines
17711830 }
17721831
17731832 out:
1774− if (sas_dev)
1775− atomic64_dec(&sas_dev->running_req);
17761833
17771834 hisi_sas_slot_task_free(hisi_hba, task, slot);
17781835 sts = ts->stat;
@@ -2020,9 +2077,12 @@ static int phy_up_v2_hw(int phy_no, struct hisi_hba *hisi_hba) · 241 unmodified lines
20202077 if (phy->identify.device_type == SAS_END_DEVICE)
20212078 phy->identify.target_port_protocols =
20222079 SAS_PROTOCOL_SSP;
2023− else if (phy->identify.device_type != SAS_PHY_UNUSED)
2080+ else if (phy->identify.device_type != SAS_PHY_UNUSED) {
20242081 phy->identify.target_port_protocols =
20252082 SAS_PROTOCOL_SMP;
2083+ if (!timer_pending(&hisi_hba->timer))
2084+ set_link_timer_quirk(hisi_hba);
2085+ }
20262086 queue_work(hisi_hba->wq, &phy->phyup_ws);
20272087
20282088 end:
@@ -2033,10 +2093,23 @@ end: · 4 unmodified lines
20332093 return res;
20342094 }
20352095
2096+static bool check_any_wideports_v2_hw(struct hisi_hba *hisi_hba)
2097+{
2098+ u32 port_state;
2099+
2100+ port_state = hisi_sas_read32(hisi_hba, PORT_STATE);
2101+ if (port_state & 0x1ff)
2102+ return true;
2103+
2104+ return false;
2105+}
2106+
20362107 static int phy_down_v2_hw(int phy_no, struct hisi_hba *hisi_hba)
20372108 {
20382109 int res = 0;
20392110 u32 phy_state, sl_ctrl, txid_auto;
2111+ struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
2112+ struct hisi_sas_port *port = phy->port;
20402113
20412114 hisi_sas_phy_write32(hisi_hba, phy_no, PHYCTRL_NOT_RDY_MSK, 1);
20422115
@@ -2046,6 +2119,10 @@ static int phy_down_v2_hw(int phy_no, struct hisi_hba *hisi_hba) · 3 unmodified lines
20462119 sl_ctrl = hisi_sas_phy_read32(hisi_hba, phy_no, SL_CONTROL);
20472120 hisi_sas_phy_write32(hisi_hba, phy_no, SL_CONTROL,
20482121 sl_ctrl & ~SL_CONTROL_CTA_MSK);
2122+ if (port && !get_wideport_bitmap_v2_hw(hisi_hba, port->id))
2123+ if (!check_any_wideports_v2_hw(hisi_hba) &&
2124+ timer_pending(&hisi_hba->timer))
2125+ del_timer(&hisi_hba->timer);
20492126
20502127 txid_auto = hisi_sas_phy_read32(hisi_hba, phy_no, TXID_AUTO);
20512128 hisi_sas_phy_write32(hisi_hba, phy_no, TXID_AUTO,
@@ -2481,21 +2558,19 @@ static irqreturn_t fatal_axi_int_v2_hw(int irq_no, void *p) · 429 unmodified lines
24812558 return IRQ_HANDLED;
24822559 }
24832560
2484−static irqreturn_t cq_interrupt_v2_hw(int irq_no, void *p)
2561+static void cq_tasklet_v2_hw(unsigned long val)
24852562 {
2486− struct hisi_sas_cq *cq = p;
2563+ struct hisi_sas_cq *cq = (struct hisi_sas_cq *)val;
24872564 struct hisi_hba *hisi_hba = cq->hisi_hba;
24882565 struct hisi_sas_slot *slot;
24892566 struct hisi_sas_itct *itct;
24902567 struct hisi_sas_complete_v2_hdr *complete_queue;
2491− u32 irq_value, rd_point = cq->rd_point, wr_point, dev_id;
2568+ u32 rd_point = cq->rd_point, wr_point, dev_id;
24922569 int queue = cq->id;
24932570
24942571 complete_queue = hisi_hba->complete_hdr[queue];
2495− irq_value = hisi_sas_read32(hisi_hba, OQ_INT_SRC);
2496−
2497− hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
24982572
2573+ spin_lock(&hisi_hba->lock);
24992574 wr_point = hisi_sas_read32(hisi_hba, COMPL_Q_0_WR_PTR +
25002575 (0x14 * queue));
25012576
@@ -2545,6 +2620,19 @@ static irqreturn_t cq_interrupt_v2_hw(int irq_no, void *p) · 43 unmodified lines
25452620 /* update rd_point */
25462621 cq->rd_point = rd_point;
25472622 hisi_sas_write32(hisi_hba, COMPL_Q_0_RD_PTR + (0x14 * queue), rd_point);
2623+ spin_unlock(&hisi_hba->lock);
2624+}
2625+
2626+static irqreturn_t cq_interrupt_v2_hw(int irq_no, void *p)
2627+{
2628+ struct hisi_sas_cq *cq = p;
2629+ struct hisi_hba *hisi_hba = cq->hisi_hba;
2630+ int queue = cq->id;
2631+
2632+ hisi_sas_write32(hisi_hba, OQ_INT_SRC, 1 << queue);
2633+
2634+ tasklet_schedule(&cq->tasklet);
2635+
25482636 return IRQ_HANDLED;
25492637 }
25502638
@@ -2726,6 +2814,8 @@ static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba) · 175 unmodified lines
27262814
27272815 for (i = 0; i < hisi_hba->queue_count; i++) {
27282816 int idx = i + 96; /* First cq interrupt is irq96 */
2817+ struct hisi_sas_cq *cq = &hisi_hba->cq[i];
2818+ struct tasklet_struct *t = &cq->tasklet;
27292819
27302820 irq = irq_map[idx];
27312821 if (!irq) {
@@ -2742,6 +2832,7 @@ static int interrupt_init_v2_hw(struct hisi_hba *hisi_hba) · 10 unmodified lines
27422832 irq, rc);
27432833 return -ENOENT;
27442834 }
2835+ tasklet_init(t, cq_tasklet_v2_hw, (unsigned long)cq);
27452836 }
27462837
27472838 return 0;
@@ -2807,6 +2898,12 @@ static int hisi_sas_v2_probe(struct platform_device *pdev) · 59 unmodified lines
28072898
28082899 static int hisi_sas_v2_remove(struct platform_device *pdev)
28092900 {
2901+ struct sas_ha_struct *sha = platform_get_drvdata(pdev);
2902+ struct hisi_hba *hisi_hba = sha->lldd_ha;
2903+
2904+ if (timer_pending(&hisi_hba->timer))
2905+ del_timer(&hisi_hba->timer);
2906+
28102907 return hisi_sas_remove(pdev);
28112908 }
28122909
drivers/scsi/hpsa.c+2−6
@@ -9263,13 +9263,9 @@ static int hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support) · 9262 unmodified lines
92639263 access = SA5_ioaccel_mode1_access;
92649264 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
92659265 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
9266− } else {
9267− if (trans_support & CFGTBL_Trans_io_accel2) {
9266+ } else
9267+ if (trans_support & CFGTBL_Trans_io_accel2)
92689268 access = SA5_ioaccel_mode2_access;
9269− writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
9270− writel(4, &h->cfgtable->HostWrite.CoalIntCount);
9271− }
9272− }
92739269 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
92749270 if (hpsa_wait_for_mode_change_ack(h)) {
92759271 dev_err(&h->pdev->dev,
drivers/scsi/hpsa.h+20−20
@@ -578,38 +578,38 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q) · 577 unmodified lines
578578 }
579579
580580 static struct access_method SA5_access = {
581− SA5_submit_command,
582− SA5_intr_mask,
583− SA5_intr_pending,
584− SA5_completed,
581+ .submit_command = SA5_submit_command,
582+ .set_intr_mask = SA5_intr_mask,
583+ .intr_pending = SA5_intr_pending,
584+ .command_completed = SA5_completed,
585585 };
586586
587587 static struct access_method SA5_ioaccel_mode1_access = {
588− SA5_submit_command,
589− SA5_performant_intr_mask,
590− SA5_ioaccel_mode1_intr_pending,
591− SA5_ioaccel_mode1_completed,
588+ .submit_command = SA5_submit_command,
589+ .set_intr_mask = SA5_performant_intr_mask,
590+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
591+ .command_completed = SA5_ioaccel_mode1_completed,
592592 };
593593
594594 static struct access_method SA5_ioaccel_mode2_access = {
595− SA5_submit_command_ioaccel2,
596− SA5_performant_intr_mask,
597− SA5_performant_intr_pending,
598− SA5_performant_completed,
595+ .submit_command = SA5_submit_command_ioaccel2,
596+ .set_intr_mask = SA5_performant_intr_mask,
597+ .intr_pending = SA5_performant_intr_pending,
598+ .command_completed = SA5_performant_completed,
599599 };
600600
601601 static struct access_method SA5_performant_access = {
602− SA5_submit_command,
603− SA5_performant_intr_mask,
604− SA5_performant_intr_pending,
605− SA5_performant_completed,
602+ .submit_command = SA5_submit_command,
603+ .set_intr_mask = SA5_performant_intr_mask,
604+ .intr_pending = SA5_performant_intr_pending,
605+ .command_completed = SA5_performant_completed,
606606 };
607607
608608 static struct access_method SA5_performant_access_no_read = {
609− SA5_submit_command_no_read,
610− SA5_performant_intr_mask,
611− SA5_performant_intr_pending,
612− SA5_performant_completed,
609+ .submit_command = SA5_submit_command_no_read,
610+ .set_intr_mask = SA5_performant_intr_mask,
611+ .intr_pending = SA5_performant_intr_pending,
612+ .command_completed = SA5_performant_completed,
613613 };
614614
615615 struct board_type {
drivers/scsi/ibmvscsi/ibmvfc.c+1−0
@@ -3090,6 +3090,7 @@ static struct scsi_host_template driver_template = { · 3089 unmodified lines
30903090 .name = "IBM POWER Virtual FC Adapter",
30913091 .proc_name = IBMVFC_NAME,
30923092 .queuecommand = ibmvfc_queuecommand,
3093+ .eh_timed_out = fc_eh_timed_out,
30933094 .eh_abort_handler = ibmvfc_eh_abort_handler,
30943095 .eh_device_reset_handler = ibmvfc_eh_device_reset_handler,
30953096 .eh_target_reset_handler = ibmvfc_eh_target_reset_handler,
drivers/scsi/ibmvscsi/ibmvscsi.c+1−0
@@ -2072,6 +2072,7 @@ static struct scsi_host_template driver_template = { · 2071 unmodified lines
20722072 .name = "IBM POWER Virtual SCSI Adapter " IBMVSCSI_VERSION,
20732073 .proc_name = "ibmvscsi",
20742074 .queuecommand = ibmvscsi_queuecommand,
2075+ .eh_timed_out = srp_timed_out,
20752076 .eh_abort_handler = ibmvscsi_eh_abort_handler,
20762077 .eh_device_reset_handler = ibmvscsi_eh_device_reset_handler,
20772078 .eh_host_reset_handler = ibmvscsi_eh_host_reset_handler,
drivers/scsi/iscsi_tcp.c+1−0
@@ -967,6 +967,7 @@ static struct scsi_host_template iscsi_sw_tcp_sht = { · 966 unmodified lines
967967 .sg_tablesize = 4096,
968968 .max_sectors = 0xFFFF,
969969 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
970+ .eh_timed_out = iscsi_eh_cmd_timed_out,
970971 .eh_abort_handler = iscsi_eh_abort,
971972 .eh_device_reset_handler= iscsi_eh_device_reset,
972973 .eh_target_reset_handler = iscsi_eh_recover_target,
drivers/scsi/libiscsi.c+2−3
@@ -1930,7 +1930,7 @@ static int iscsi_has_ping_timed_out(struct iscsi_conn *conn) · 1929 unmodified lines
19301930 return 0;
19311931 }
19321932
1933−static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
1933+enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
19341934 {
19351935 enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED;
19361936 struct iscsi_task *task = NULL, *running_task;
@@ -2063,6 +2063,7 @@ done: · 126 unmodified lines
20632063 "timer reset" : "nh");
20642064 return rc;
20652065 }
2066+EXPORT_SYMBOL_GPL(iscsi_eh_cmd_timed_out);
20662067
20672068 static void iscsi_check_transport_timeouts(unsigned long data)
20682069 {
@@ -2585,8 +2586,6 @@ int iscsi_host_add(struct Scsi_Host *shost, struct device *pdev) · 516 unmodified lines
25852586 if (!shost->cmd_per_lun)
25862587 shost->cmd_per_lun = ISCSI_DEF_CMD_PER_LUN;
25872588
2588− if (!shost->transportt->eh_timed_out)
2589− shost->transportt->eh_timed_out = iscsi_eh_cmd_timed_out;
25902589 return scsi_add_host(shost, pdev);
25912590 }
25922591 EXPORT_SYMBOL_GPL(iscsi_host_add);
drivers/scsi/libsas/sas_init.c+0−1
@@ -560,7 +560,6 @@ sas_domain_attach_transport(struct sas_domain_function_template *dft) · 559 unmodified lines
560560 i = to_sas_internal(stt);
561561 i->dft = dft;
562562 stt->create_work_queue = 1;
563− stt->eh_timed_out = sas_scsi_timed_out;
564563 stt->eh_strategy_handler = sas_scsi_recover_host;
565564
566565 return stt;
drivers/scsi/libsas/sas_internal.h+0−2
@@ -64,8 +64,6 @@ void sas_unregister_phys(struct sas_ha_struct *sas_ha); · 63 unmodified lines
6464 int sas_register_ports(struct sas_ha_struct *sas_ha);
6565 void sas_unregister_ports(struct sas_ha_struct *sas_ha);
6666
67−enum blk_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *);
68−
6967 int sas_init_events(struct sas_ha_struct *sas_ha);
7068 void sas_disable_revalidation(struct sas_ha_struct *ha);
7169 void sas_enable_revalidation(struct sas_ha_struct *ha);
drivers/scsi/libsas/sas_scsi_host.c+0−7
@@ -803,13 +803,6 @@ out: · 802 unmodified lines
803803 shost->host_failed, tries);
804804 }
805805
806−enum blk_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
807−{
808− scmd_dbg(cmd, "command %p timed out\n", cmd);
809−
810− return BLK_EH_NOT_HANDLED;
811−}
812−
813806 int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
814807 {
815808 struct domain_device *dev = sdev_to_domain_dev(sdev);
drivers/scsi/lpfc/lpfc.h+0−1
@@ -727,7 +727,6 @@ struct lpfc_hba { · 726 unmodified lines
727727 uint32_t cfg_fcp_io_channel;
728728 uint32_t cfg_total_seg_cnt;
729729 uint32_t cfg_sg_seg_cnt;
730− uint32_t cfg_prot_sg_seg_cnt;
731730 uint32_t cfg_sg_dma_buf_size;
732731 uint64_t cfg_soft_wwnn;
733732 uint64_t cfg_soft_wwpn;
drivers/scsi/lpfc/lpfc_attr.c+41−20
@@ -2073,6 +2073,13 @@ lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr, · 2072 unmodified lines
20732073 return -EINVAL;
20742074
20752075 phba->soft_wwn_enable = 1;
2076+
2077+ dev_printk(KERN_WARNING, &phba->pcidev->dev,
2078+ "lpfc%d: soft_wwpn assignment has been enabled.\n",
2079+ phba->brd_no);
2080+ dev_printk(KERN_WARNING, &phba->pcidev->dev,
2081+ " The soft_wwpn feature is not supported by Broadcom.");
2082+
20762083 return count;
20772084 }
20782085 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
@@ -2143,7 +2150,7 @@ lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr, · 64 unmodified lines
21432150 phba->soft_wwn_enable = 0;
21442151
21452152 rc = lpfc_wwn_set(buf, cnt, wwpn);
2146− if (!rc) {
2153+ if (rc) {
21472154 /* not able to set wwpn, unlock it */
21482155 phba->soft_wwn_enable = 1;
21492156 return rc;
@@ -2224,7 +2231,7 @@ lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr, · 74 unmodified lines
22242231 return -EINVAL;
22252232
22262233 rc = lpfc_wwn_set(buf, cnt, wwnn);
2227− if (!rc) {
2234+ if (rc) {
22282235 /* Allow wwnn to be set many times, as long as the enable
22292236 * is set. However, once the wwpn is set, everything locks.
22302237 */
@@ -2435,7 +2442,8 @@ lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr, · 204 unmodified lines
24352442 else
24362443 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
24372444 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2438− phba->cfg_oas_priority = phba->cfg_XLanePriority;
2445+ if (phba->cfg_oas_priority == 0)
2446+ phba->cfg_oas_priority = phba->cfg_XLanePriority;
24392447 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
24402448 return count;
24412449 }
@@ -2561,7 +2569,7 @@ lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[], · 119 unmodified lines
25612569 rc = -ENOMEM;
25622570 } else {
25632571 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2564− (struct lpfc_name *)tgt_wwpn, lun);
2572+ (struct lpfc_name *)tgt_wwpn, lun, pri);
25652573 }
25662574 return rc;
25672575
@@ -2585,7 +2593,8 @@ lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[], · 17 unmodified lines
25852593 */
25862594 static uint64_t
25872595 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2588− uint8_t tgt_wwpn[], uint32_t *lun_status)
2596+ uint8_t tgt_wwpn[], uint32_t *lun_status,
2597+ uint32_t *lun_pri)
25892598 {
25902599 uint64_t found_lun;
25912600
@@ -2598,7 +2607,7 @@ lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[], · 6 unmodified lines
25982607 &phba->sli4_hba.oas_next_lun,
25992608 (struct lpfc_name *)vpt_wwpn,
26002609 (struct lpfc_name *)tgt_wwpn,
2601− &found_lun, lun_status))
2610+ &found_lun, lun_status, lun_pri))
26022611 return found_lun;
26032612 else
26042613 return NOT_OAS_ENABLED_LUN;
@@ -2670,7 +2679,8 @@ lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr, · 65 unmodified lines
26702679
26712680 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
26722681 phba->cfg_oas_tgt_wwpn,
2673− &phba->cfg_oas_lun_status);
2682+ &phba->cfg_oas_lun_status,
2683+ &phba->cfg_oas_priority);
26742684 if (oas_lun != NOT_OAS_ENABLED_LUN)
26752685 phba->cfg_oas_flags |= OAS_LUN_VALID;
26762686
@@ -2701,6 +2711,7 @@ lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr, · 24 unmodified lines
27012711 struct Scsi_Host *shost = class_to_shost(dev);
27022712 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
27032713 uint64_t scsi_lun;
2714+ uint32_t pri;
27042715 ssize_t rc;
27052716
27062717 if (!phba->cfg_fof)
@@ -2718,17 +2729,20 @@ lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr, · 11 unmodified lines
27182729 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
27192730 return -EINVAL;
27202731
2732+ pri = phba->cfg_oas_priority;
2733+ if (pri == 0)
2734+ pri = phba->cfg_XLanePriority;
2735+
27212736 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
27222737 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
27232738 "priority 0x%x with oas state %d\n",
27242739 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
27252740 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
2726− phba->cfg_oas_priority, phba->cfg_oas_lun_state);
2741+ pri, phba->cfg_oas_lun_state);
27272742
27282743 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
27292744 phba->cfg_oas_tgt_wwpn, scsi_lun,
2730− phba->cfg_oas_lun_state,
2731− phba->cfg_oas_priority);
2745+ phba->cfg_oas_lun_state, pri);
27322746 if (rc)
27332747 return rc;
27342748
@@ -4669,14 +4683,6 @@ LPFC_ATTR(delay_discovery, 0, 0, 1, · 1934 unmodified lines
46694683 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
46704684 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
46714685
4672−/*
4673− * This parameter will be depricated, the driver cannot limit the
4674− * protection data s/g list.
4675− */
4676−LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4677− LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4678− "Max Protection Scatter Gather Segment Count");
4679−
46804686 /*
46814687 * lpfc_enable_mds_diags: Enable MDS Diagnostics
46824688 * 0 = MDS Diagnostics disabled (default)
@@ -4766,7 +4772,6 @@ struct device_attribute *lpfc_hba_attrs[] = { · 83 unmodified lines
47664772 &dev_attr_lpfc_sg_seg_cnt,
47674773 &dev_attr_lpfc_max_scsicmpl_time,
47684774 &dev_attr_lpfc_stat_data_ctrl,
4769− &dev_attr_lpfc_prot_sg_seg_cnt,
47704775 &dev_attr_lpfc_aer_support,
47714776 &dev_attr_lpfc_aer_state_cleanup,
47724777 &dev_attr_lpfc_sriov_nr_virtfn,
@@ -5060,6 +5065,19 @@ lpfc_free_sysfs_attr(struct lpfc_vport *vport) · 287 unmodified lines
50605065 * Dynamic FC Host Attributes Support
50615066 */
50625067
5068+/**
5069+ * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5070+ * @shost: kernel scsi host pointer.
5071+ **/
5072+static void
5073+lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5074+{
5075+ struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5076+
5077+ lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5078+ sizeof fc_host_symbolic_name(shost));
5079+}
5080+
50635081 /**
50645082 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
50655083 * @shost: kernel scsi host pointer.
@@ -5597,6 +5615,8 @@ struct fc_function_template lpfc_transport_functions = { · 531 unmodified lines
55975615 .show_host_supported_fc4s = 1,
55985616 .show_host_supported_speeds = 1,
55995617 .show_host_maxframe_size = 1,
5618+
5619+ .get_host_symbolic_name = lpfc_get_host_symbolic_name,
56005620 .show_host_symbolic_name = 1,
56015621
56025622 /* dynamic attributes the driver supports */
@@ -5664,6 +5684,8 @@ struct fc_function_template lpfc_vport_transport_functions = { · 61 unmodified lines
56645684 .show_host_supported_fc4s = 1,
56655685 .show_host_supported_speeds = 1,
56665686 .show_host_maxframe_size = 1,
5687+
5688+ .get_host_symbolic_name = lpfc_get_host_symbolic_name,
56675689 .show_host_symbolic_name = 1,
56685690
56695691 /* dynamic attributes the driver supports */
@@ -5768,7 +5790,6 @@ lpfc_get_cfgparam(struct lpfc_hba *phba) · 98 unmodified lines
57685790 phba->cfg_soft_wwnn = 0L;
57695791 phba->cfg_soft_wwpn = 0L;
57705792 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
5771− lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
57725793 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
57735794 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
57745795 lpfc_aer_support_init(phba, lpfc_aer_support);
drivers/scsi/lpfc/lpfc_crtn.h+4−3
@@ -480,7 +480,7 @@ void lpfc_sli4_offline_eratt(struct lpfc_hba *); · 479 unmodified lines
480480 struct lpfc_device_data *lpfc_create_device_data(struct lpfc_hba *,
481481 struct lpfc_name *,
482482 struct lpfc_name *,
483− uint64_t, bool);
483+ uint64_t, uint32_t, bool);
484484 void lpfc_delete_device_data(struct lpfc_hba *, struct lpfc_device_data*);
485485 struct lpfc_device_data *__lpfc_get_device_data(struct lpfc_hba *,
486486 struct list_head *list,
@@ -489,9 +489,10 @@ struct lpfc_device_data *__lpfc_get_device_data(struct lpfc_hba *, · 2 unmodified lines
489489 bool lpfc_enable_oas_lun(struct lpfc_hba *, struct lpfc_name *,
490490 struct lpfc_name *, uint64_t, uint8_t);
491491 bool lpfc_disable_oas_lun(struct lpfc_hba *, struct lpfc_name *,
492− struct lpfc_name *, uint64_t);
492+ struct lpfc_name *, uint64_t, uint8_t);
493493 bool lpfc_find_next_oas_lun(struct lpfc_hba *, struct lpfc_name *,
494494 struct lpfc_name *, uint64_t *, struct lpfc_name *,
495− struct lpfc_name *, uint64_t *, uint32_t *);
495+ struct lpfc_name *, uint64_t *,
496+ uint32_t *, uint32_t *);
496497 int lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox);
497498 void lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb);
drivers/scsi/lpfc/lpfc_els.c+7−2
@@ -1999,6 +1999,9 @@ lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry) · 1998 unmodified lines
19991999 if (sp->cmn.fcphHigh < FC_PH3)
20002000 sp->cmn.fcphHigh = FC_PH3;
20012001
2002+ sp->cmn.valid_vendor_ver_level = 0;
2003+ memset(sp->vendorVersion, 0, sizeof(sp->vendorVersion));
2004+
20022005 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
20032006 "Issue PLOGI: did:x%x",
20042007 did, 0, 0);
@@ -3990,6 +3993,9 @@ lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag, · 1985 unmodified lines
39903993 } else {
39913994 memcpy(pcmd, &vport->fc_sparam,
39923995 sizeof(struct serv_parm));
3996+
3997+ sp->cmn.valid_vendor_ver_level = 0;
3998+ memset(sp->vendorVersion, 0, sizeof(sp->vendorVersion));
39933999 }
39944000
39954001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
@@ -8851,8 +8857,7 @@ lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, · 4855 unmodified lines
88518857 {
88528858 struct ls_rjt stat;
88538859
8854− if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
8855− BUG();
8860+ BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
88568861
88578862 switch (rspiocb->iocb.ulpStatus) {
88588863 case IOSTAT_NPORT_RJT:
drivers/scsi/lpfc/lpfc_hw.h+6−0
@@ -360,6 +360,12 @@ struct csp { · 359 unmodified lines
360360 * Word 1 Bit 30 in PLOGI request is random offset
361361 */
362362 #define virtual_fabric_support randomOffset /* Word 1, bit 30 */
363+/*
364+ * Word 1 Bit 29 in common service parameter is overloaded.
365+ * Word 1 Bit 29 in FLOGI response is multiple NPort assignment
366+ * Word 1 Bit 29 in FLOGI/PLOGI request is Valid Vendor Version Level
367+ */
368+#define valid_vendor_ver_level response_multiple_NPort /* Word 1, bit 29 */
363369 #ifdef __BIG_ENDIAN_BITFIELD
364370 uint16_t request_multiple_Nport:1; /* FC Word 1, bit 31 */
365371 uint16_t randomOffset:1; /* FC Word 1, bit 30 */
drivers/scsi/lpfc/lpfc_scsi.c+14−6
@@ -5452,7 +5452,9 @@ lpfc_slave_alloc(struct scsi_device *sdev) · 5451 unmodified lines
54525452 device_data = lpfc_create_device_data(phba,
54535453 &vport->fc_portname,
54545454 &target_wwpn,
5455− sdev->lun, true);
5455+ sdev->lun,
5456+ phba->cfg_XLanePriority,
5457+ true);
54565458 if (!device_data)
54575459 return -ENOMEM;
54585460 spin_lock_irqsave(&phba->devicelock, flags);
@@ -5587,7 +5589,7 @@ lpfc_slave_destroy(struct scsi_device *sdev) · 128 unmodified lines
55875589 struct lpfc_device_data*
55885590 lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
55895591 struct lpfc_name *target_wwpn, uint64_t lun,
5590− bool atomic_create)
5592+ uint32_t pri, bool atomic_create)
55915593 {
55925594
55935595 struct lpfc_device_data *lun_info;
@@ -5614,7 +5616,7 @@ lpfc_create_device_data(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, · 20 unmodified lines
56145616 sizeof(struct lpfc_name));
56155617 lun_info->device_id.lun = lun;
56165618 lun_info->oas_enabled = false;
5617− lun_info->priority = phba->cfg_XLanePriority;
5619+ lun_info->priority = pri;
56185620 lun_info->available = false;
56195621 return lun_info;
56205622 }
@@ -5716,7 +5718,8 @@ lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, · 95 unmodified lines
57165718 struct lpfc_name *found_vport_wwpn,
57175719 struct lpfc_name *found_target_wwpn,
57185720 uint64_t *found_lun,
5719− uint32_t *found_lun_status)
5721+ uint32_t *found_lun_status,
5722+ uint32_t *found_lun_pri)
57205723 {
57215724
57225725 unsigned long flags;
@@ -5763,6 +5766,7 @@ lpfc_find_next_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, · 40 unmodified lines
57635766 OAS_LUN_STATUS_EXISTS;
57645767 else
57655768 *found_lun_status = 0;
5769+ *found_lun_pri = lun_info->priority;
57665770 if (phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)
57675771 memset(vport_wwpn, 0x0,
57685772 sizeof(struct lpfc_name));
@@ -5824,13 +5828,14 @@ lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, · 55 unmodified lines
58245828 if (lun_info) {
58255829 if (!lun_info->oas_enabled)
58265830 lun_info->oas_enabled = true;
5831+ lun_info->priority = pri;
58275832 spin_unlock_irqrestore(&phba->devicelock, flags);
58285833 return true;
58295834 }
58305835
58315836 /* Create an lun info structure and add to list of luns */
58325837 lun_info = lpfc_create_device_data(phba, vport_wwpn, target_wwpn, lun,
5833− false);
5838+ pri, false);
58345839 if (lun_info) {
58355840 lun_info->oas_enabled = true;
58365841 lun_info->priority = pri;
@@ -5864,7 +5869,7 @@ lpfc_enable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, · 27 unmodified lines
58645869 **/
58655870 bool
58665871 lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn,
5867− struct lpfc_name *target_wwpn, uint64_t lun)
5872+ struct lpfc_name *target_wwpn, uint64_t lun, uint8_t pri)
58685873 {
58695874
58705875 struct lpfc_device_data *lun_info;
@@ -5882,6 +5887,7 @@ lpfc_disable_oas_lun(struct lpfc_hba *phba, struct lpfc_name *vport_wwpn, · 11 unmodified lines
58825887 target_wwpn, lun);
58835888 if (lun_info) {
58845889 lun_info->oas_enabled = false;
5890+ lun_info->priority = pri;
58855891 if (!lun_info->available)
58865892 lpfc_delete_device_data(phba, lun_info);
58875893 spin_unlock_irqrestore(&phba->devicelock, flags);
@@ -5923,6 +5929,7 @@ struct scsi_host_template lpfc_template = { · 35 unmodified lines
59235929 .proc_name = LPFC_DRIVER_NAME,
59245930 .info = lpfc_info,
59255931 .queuecommand = lpfc_queuecommand,
5932+ .eh_timed_out = fc_eh_timed_out,
59265933 .eh_abort_handler = lpfc_abort_handler,
59275934 .eh_device_reset_handler = lpfc_device_reset_handler,
59285935 .eh_target_reset_handler = lpfc_target_reset_handler,
@@ -5949,6 +5956,7 @@ struct scsi_host_template lpfc_vport_template = { · 20 unmodified lines
59495956 .proc_name = LPFC_DRIVER_NAME,
59505957 .info = lpfc_info,
59515958 .queuecommand = lpfc_queuecommand,
5959+ .eh_timed_out = fc_eh_timed_out,
59525960 .eh_abort_handler = lpfc_abort_handler,
59535961 .eh_device_reset_handler = lpfc_device_reset_handler,
59545962 .eh_target_reset_handler = lpfc_target_reset_handler,
drivers/scsi/lpfc/lpfc_sli.c+9−4
@@ -120,6 +120,8 @@ lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) · 119 unmodified lines
120120 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
121121 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
122122 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
123+ /* ensure WQE bcopy flushed before doorbell write */
124+ wmb();
123125
124126 /* Update the host index before invoking device */
125127 host_index = q->host_index;
@@ -6313,7 +6315,8 @@ lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) · 6187 unmodified lines
63136315 LPFC_SLI4_MBX_EMBED);
63146316
63156317 mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION;
6316− mbox->u.mqe.un.set_host_data.param_len = 8;
6318+ mbox->u.mqe.un.set_host_data.param_len =
6319+ LPFC_HOST_OS_DRIVER_VERSION_SIZE;
63176320 snprintf(mbox->u.mqe.un.set_host_data.data,
63186321 LPFC_HOST_OS_DRIVER_VERSION_SIZE,
63196322 "Linux %s v"LPFC_DRIVER_VERSION,
@@ -10035,6 +10038,7 @@ lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, · 3715 unmodified lines
1003510038 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
1003610039
1003710040 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
10041+ abtsiocbp->vport = vport;
1003810042
1003910043 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
1004010044 "0339 Abort xri x%x, original iotag x%x, "
@@ -17226,7 +17230,8 @@ lpfc_drain_txq(struct lpfc_hba *phba) · 7185 unmodified lines
1722617230 unsigned long iflags = 0;
1722717231 char *fail_msg = NULL;
1722817232 struct lpfc_sglq *sglq;
17229− union lpfc_wqe wqe;
17233+ union lpfc_wqe128 wqe128;
17234+ union lpfc_wqe *wqe = (union lpfc_wqe *) &wqe128;
1723017235 uint32_t txq_cnt = 0;
1723117236
1723217237 spin_lock_irqsave(&pring->ring_lock, iflags);
@@ -17265,9 +17270,9 @@ lpfc_drain_txq(struct lpfc_hba *phba) · 32 unmodified lines
1726517270 piocbq->sli4_xritag = sglq->sli4_xritag;
1726617271 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
1726717272 fail_msg = "to convert bpl to sgl";
17268− else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
17273+ else if (lpfc_sli4_iocb2wqe(phba, piocbq, wqe))
1726917274 fail_msg = "to convert iocb to wqe";
17270− else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe))
17275+ else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe))
1727117276 fail_msg = " - Wq is full";
1727217277 else
1727317278 lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
drivers/scsi/lpfc/lpfc_version.h+1−1
@@ -18,7 +18,7 @@ · 17 unmodified lines
1818 * included with this package. *
1919 *******************************************************************/
2020
21−#define LPFC_DRIVER_VERSION "11.2.0.2"
21+#define LPFC_DRIVER_VERSION "11.2.0.4"
2222 #define LPFC_DRIVER_NAME "lpfc"
2323
2424 /* Used for SLI 2/3 */
drivers/scsi/lpfc/lpfc_vport.c+8−0
@@ -537,6 +537,12 @@ enable_vport(struct fc_vport *fc_vport) · 536 unmodified lines
537537
538538 spin_lock_irq(shost->host_lock);
539539 vport->load_flag |= FC_LOADING;
540+ if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
541+ spin_unlock_irq(shost->host_lock);
542+ lpfc_issue_init_vpi(vport);
543+ goto out;
544+ }
545+
540546 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
541547 spin_unlock_irq(shost->host_lock);
542548
@@ -557,6 +563,8 @@ enable_vport(struct fc_vport *fc_vport) · 14 unmodified lines
557563 } else {
558564 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
559565 }
566+
567+out:
560568 lpfc_printf_vlog(vport, KERN_ERR, LOG_VPORT,
561569 "1827 Vport Enabled.\n");
562570 return VPORT_OK;
drivers/scsi/mac_scsi.c+4−4
@@ -154,7 +154,7 @@ __asm__ __volatile__ \ · 153 unmodified lines
154154 static inline int macscsi_pread(struct NCR5380_hostdata *hostdata,
155155 unsigned char *dst, int len)
156156 {
157− unsigned char *s = hostdata->pdma_io + (INPUT_DATA_REG << 4);
157+ u8 __iomem *s = hostdata->pdma_io + (INPUT_DATA_REG << 4);
158158 unsigned char *d = dst;
159159 int n = len;
160160 int transferred;
@@ -257,7 +257,7 @@ static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata, · 96 unmodified lines
257257 unsigned char *src, int len)
258258 {
259259 unsigned char *s = src;
260− unsigned char *d = hostdata->pdma_io + (OUTPUT_DATA_REG << 4);
260+ u8 __iomem *d = hostdata->pdma_io + (OUTPUT_DATA_REG << 4);
261261 int n = len;
262262 int transferred;
263263
@@ -381,10 +381,10 @@ static int __init mac_scsi_probe(struct platform_device *pdev) · 117 unmodified lines
381381
382382 hostdata = shost_priv(instance);
383383 hostdata->base = pio_mem->start;
384− hostdata->io = (void *)pio_mem->start;
384+ hostdata->io = (u8 __iomem *)pio_mem->start;
385385
386386 if (pdma_mem && setup_use_pdma)
387− hostdata->pdma_io = (void *)pdma_mem->start;
387+ hostdata->pdma_io = (u8 __iomem *)pdma_mem->start;
388388 else
389389 host_flags |= FLAG_NO_PSEUDO_DMA;
390390
drivers/scsi/megaraid/megaraid_sas.h+153−46
@@ -35,8 +35,8 @@ · 34 unmodified lines
3535 /*
3636 * MegaRAID SAS Driver meta data
3737 */
38−#define MEGASAS_VERSION "06.812.07.00-rc1"
39−#define MEGASAS_RELDATE "August 22, 2016"
38+#define MEGASAS_VERSION "07.701.16.00-rc1"
39+#define MEGASAS_RELDATE "February 2, 2017"
4040
4141 /*
4242 * Device IDs
@@ -56,6 +56,11 @@ · 13 unmodified lines
5656 #define PCI_DEVICE_ID_LSI_INTRUDER_24 0x00cf
5757 #define PCI_DEVICE_ID_LSI_CUTLASS_52 0x0052
5858 #define PCI_DEVICE_ID_LSI_CUTLASS_53 0x0053
59+#define PCI_DEVICE_ID_LSI_VENTURA 0x0014
60+#define PCI_DEVICE_ID_LSI_HARPOON 0x0016
61+#define PCI_DEVICE_ID_LSI_TOMCAT 0x0017
62+#define PCI_DEVICE_ID_LSI_VENTURA_4PORT 0x001B
63+#define PCI_DEVICE_ID_LSI_CRUSADER_4PORT 0x001C
5964
6065 /*
6166 * Intel HBA SSDIDs
@@ -100,7 +105,7 @@ · 38 unmodified lines
100105 */
101106
102107 /*
103− * MFI stands for MegaRAID SAS FW Interface. This is just a moniker for
108+ * MFI stands for MegaRAID SAS FW Interface. This is just a moniker for
104109 * protocol between the software and firmware. Commands are issued using
105110 * "message frames"
106111 */
@@ -690,6 +695,18 @@ struct MR_PD_INFO { · 583 unmodified lines
690695 u8 reserved1[512-428];
691696 } __packed;
692697
698+/*
699+ * Definition of structure used to expose attributes of VD or JBOD
700+ * (this structure is to be filled by firmware when MR_DCMD_DRV_GET_TARGET_PROP
701+ * is fired by driver)
702+ */
703+struct MR_TARGET_PROPERTIES {
704+ u32 max_io_size_kb;
705+ u32 device_qdepth;
706+ u32 sector_size;
707+ u8 reserved[500];
708+} __packed;
709+
693710 /*
694711 * defines the physical drive address structure
695712 */
@@ -728,7 +745,6 @@ struct megasas_pd_list { · 32 unmodified lines
728745 u16 tid;
729746 u8 driveType;
730747 u8 driveState;
731− u8 interface;
732748 } __packed;
733749
734750 /*
@@ -1312,7 +1328,55 @@ struct megasas_ctrl_info { · 577 unmodified lines
13121328 #endif
13131329 } adapterOperations3;
13141330
1315− u8 pad[0x800-0x7EC];
1331+ struct {
1332+#if defined(__BIG_ENDIAN_BITFIELD)
1333+ u8 reserved:7;
1334+ /* Indicates whether the CPLD image is part of
1335+ * the package and stored in flash
1336+ */
1337+ u8 cpld_in_flash:1;
1338+#else
1339+ u8 cpld_in_flash:1;
1340+ u8 reserved:7;
1341+#endif
1342+ u8 reserved1[3];
1343+ /* Null terminated string. Has the version
1344+ * information if cpld_in_flash = FALSE
1345+ */
1346+ u8 userCodeDefinition[12];
1347+ } cpld; /* Valid only if upgradableCPLD is TRUE */
1348+
1349+ struct {
1350+ #if defined(__BIG_ENDIAN_BITFIELD)
1351+ u16 reserved:8;
1352+ u16 fw_swaps_bbu_vpd_info:1;
1353+ u16 support_pd_map_target_id:1;
1354+ u16 support_ses_ctrl_in_multipathcfg:1;
1355+ u16 image_upload_supported:1;
1356+ u16 support_encrypted_mfc:1;
1357+ u16 supported_enc_algo:1;
1358+ u16 support_ibutton_less:1;
1359+ u16 ctrl_info_ext_supported:1;
1360+ #else
1361+
1362+ u16 ctrl_info_ext_supported:1;
1363+ u16 support_ibutton_less:1;
1364+ u16 supported_enc_algo:1;
1365+ u16 support_encrypted_mfc:1;
1366+ u16 image_upload_supported:1;
1367+ /* FW supports LUN based association and target port based */
1368+ u16 support_ses_ctrl_in_multipathcfg:1;
1369+ /* association for the SES device connected in multipath mode */
1370+ /* FW defines Jbod target Id within MR_PD_CFG_SEQ */
1371+ u16 support_pd_map_target_id:1;
1372+ /* FW swaps relevant fields in MR_BBU_VPD_INFO_FIXED to
1373+ * provide the data in little endian order
1374+ */
1375+ u16 fw_swaps_bbu_vpd_info:1;
1376+ u16 reserved:8;
1377+ #endif
1378+ } adapter_operations4;
1379+ u8 pad[0x800 - 0x7FE]; /* 0x7FE pad to 2K for expansion */
13161380 } __packed;
13171381
13181382 /*
@@ -1339,12 +1403,15 @@ struct megasas_ctrl_info { · 20 unmodified lines
13391403
13401404 #define MEGASAS_FW_BUSY 1
13411405
1342−#define VD_EXT_DEBUG 0
1406+/* Driver's internal Logging levels*/
1407+#define OCR_LOGS (1 << 0)
13431408
13441409 #define SCAN_PD_CHANNEL 0x1
13451410 #define SCAN_VD_CHANNEL 0x2
13461411
13471412 #define MEGASAS_KDUMP_QUEUE_DEPTH 100
1413+#define MR_LARGE_IO_MIN_SIZE (32 * 1024)
1414+#define MR_R1_LDIO_PIGGYBACK_DEFAULT 4
13481415
13491416 enum MR_SCSI_CMD_TYPE {
13501417 READ_WRITE_LDIO = 0,
@@ -1391,7 +1458,7 @@ enum FW_BOOT_CONTEXT { · 40 unmodified lines
13911458 */
13921459 #define MEGASAS_INT_CMDS 32
13931460 #define MEGASAS_SKINNY_INT_CMDS 5
1394−#define MEGASAS_FUSION_INTERNAL_CMDS 5
1461+#define MEGASAS_FUSION_INTERNAL_CMDS 8
13951462 #define MEGASAS_FUSION_IOCTL_CMDS 3
13961463 #define MEGASAS_MFI_IOCTL_CMDS 27
13971464
@@ -1429,13 +1496,19 @@ enum FW_BOOT_CONTEXT { · 31 unmodified lines
14291496 #define MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT 14
14301497 #define MR_MAX_MSIX_REG_ARRAY 16
14311498 #define MR_RDPQ_MODE_OFFSET 0X00800000
1499+
1500+#define MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT 16
1501+#define MR_MAX_RAID_MAP_SIZE_MASK 0x1FF
1502+#define MR_MIN_MAP_SIZE 0x10000
1503+/* 64k */
1504+
14321505 #define MR_CAN_HANDLE_SYNC_CACHE_OFFSET 0X01000000
14331506
14341507 /*
14351508 * register set for both 1068 and 1078 controllers
14361509 * structure extended for 1078 registers
14371510 */
1438−
1511+
14391512 struct megasas_register_set {
14401513 u32 doorbell; /*0000h*/
14411514 u32 fusion_seq_offset; /*0004h*/
@@ -1471,14 +1544,14 @@ struct megasas_register_set { · 29 unmodified lines
14711544 u32 outbound_scratch_pad ; /*00B0h*/
14721545 u32 outbound_scratch_pad_2; /*00B4h*/
14731546 u32 outbound_scratch_pad_3; /*00B8h*/
1547+ u32 outbound_scratch_pad_4; /*00BCh*/
14741548
1475− u32 reserved_4; /*00BCh*/
14761549
14771550 u32 inbound_low_queue_port ; /*00C0h*/
14781551
14791552 u32 inbound_high_queue_port ; /*00C4h*/
14801553
1481− u32 reserved_5; /*00C8h*/
1554+ u32 inbound_single_queue_port; /*00C8h*/
14821555 u32 res_6[11]; /*CCh*/
14831556 u32 host_diag;
14841557 u32 seq_offset;
@@ -1544,33 +1617,35 @@ union megasas_sgl_frame { · 59 unmodified lines
15441617 typedef union _MFI_CAPABILITIES {
15451618 struct {
15461619 #if defined(__BIG_ENDIAN_BITFIELD)
1547− u32 reserved:20;
1548− u32 support_qd_throttling:1;
1549− u32 support_fp_rlbypass:1;
1550− u32 support_vfid_in_ioframe:1;
1551− u32 support_ext_io_size:1;
1552− u32 support_ext_queue_depth:1;
1553− u32 security_protocol_cmds_fw:1;
1554− u32 support_core_affinity:1;
1555− u32 support_ndrive_r1_lb:1;
1556− u32 support_max_255lds:1;
1557− u32 support_fastpath_wb:1;
1558− u32 support_additional_msix:1;
1559− u32 support_fp_remote_lun:1;
1620+ u32 reserved:19;
1621+ u32 support_pd_map_target_id:1;
1622+ u32 support_qd_throttling:1;
1623+ u32 support_fp_rlbypass:1;
1624+ u32 support_vfid_in_ioframe:1;
1625+ u32 support_ext_io_size:1;
1626+ u32 support_ext_queue_depth:1;
1627+ u32 security_protocol_cmds_fw:1;
1628+ u32 support_core_affinity:1;
1629+ u32 support_ndrive_r1_lb:1;
1630+ u32 support_max_255lds:1;
1631+ u32 support_fastpath_wb:1;
1632+ u32 support_additional_msix:1;
1633+ u32 support_fp_remote_lun:1;
15601634 #else
1561− u32 support_fp_remote_lun:1;
1562− u32 support_additional_msix:1;
1563− u32 support_fastpath_wb:1;
1564− u32 support_max_255lds:1;
1565− u32 support_ndrive_r1_lb:1;
1566− u32 support_core_affinity:1;
1567− u32 security_protocol_cmds_fw:1;
1568− u32 support_ext_queue_depth:1;
1569− u32 support_ext_io_size:1;
1570− u32 support_vfid_in_ioframe:1;
1571− u32 support_fp_rlbypass:1;
1572− u32 support_qd_throttling:1;
1573− u32 reserved:20;
1635+ u32 support_fp_remote_lun:1;
1636+ u32 support_additional_msix:1;
1637+ u32 support_fastpath_wb:1;
1638+ u32 support_max_255lds:1;
1639+ u32 support_ndrive_r1_lb:1;
1640+ u32 support_core_affinity:1;
1641+ u32 security_protocol_cmds_fw:1;
1642+ u32 support_ext_queue_depth:1;
1643+ u32 support_ext_io_size:1;
1644+ u32 support_vfid_in_ioframe:1;
1645+ u32 support_fp_rlbypass:1;
1646+ u32 support_qd_throttling:1;
1647+ u32 support_pd_map_target_id:1;
1648+ u32 reserved:19;
15741649 #endif
15751650 } mfi_capabilities;
15761651 __le32 reg;
@@ -1803,6 +1878,8 @@ union megasas_frame { · 226 unmodified lines
18031878 struct MR_PRIV_DEVICE {
18041879 bool is_tm_capable;
18051880 bool tm_busy;
1881+ atomic_t r1_ldio_hint;
1882+ u8 interface_type;
18061883 };
18071884 struct megasas_cmd;
18081885
@@ -1994,17 +2071,24 @@ struct MR_DRV_SYSTEM_INFO { · 185 unmodified lines
19942071 };
19952072
19962073 enum MR_PD_TYPE {
1997− UNKNOWN_DRIVE = 0,
1998− PARALLEL_SCSI = 1,
1999− SAS_PD = 2,
2000− SATA_PD = 3,
2001− FC_PD = 4,
2074+ UNKNOWN_DRIVE = 0,
2075+ PARALLEL_SCSI = 1,
2076+ SAS_PD = 2,
2077+ SATA_PD = 3,
2078+ FC_PD = 4,
2079+ NVME_PD = 5,
20022080 };
20032081
20042082 /* JBOD Queue depth definitions */
20052083 #define MEGASAS_SATA_QD 32
20062084 #define MEGASAS_SAS_QD 64
20072085 #define MEGASAS_DEFAULT_PD_QD 64
2086+#define MEGASAS_NVME_QD 32
2087+
2088+#define MR_DEFAULT_NVME_PAGE_SIZE 4096
2089+#define MR_DEFAULT_NVME_PAGE_SHIFT 12
2090+#define MR_DEFAULT_NVME_MDTS_KB 128
2091+#define MR_NVME_PAGE_SIZE_MASK 0x000000FF
20082092
20092093 struct megasas_instance {
20102094
@@ -2022,6 +2106,8 @@ struct megasas_instance { · 11 unmodified lines
20222106 dma_addr_t hb_host_mem_h;
20232107 struct MR_PD_INFO *pd_info;
20242108 dma_addr_t pd_info_h;
2109+ struct MR_TARGET_PROPERTIES *tgt_prop;
2110+ dma_addr_t tgt_prop_h;
20252111
20262112 __le32 *reply_queue;
20272113 dma_addr_t reply_queue_h;
@@ -2039,6 +2125,7 @@ struct megasas_instance { · 11 unmodified lines
20392125 u32 crash_dump_drv_support;
20402126 u32 crash_dump_app_support;
20412127 u32 secure_jbod_support;
2128+ u32 support_morethan256jbod; /* FW support for more than 256 PD/JBOD */
20422129 bool use_seqnum_jbod_fp; /* Added for PD sequence */
20432130 spinlock_t crashdump_lock;
20442131
@@ -2051,6 +2138,7 @@ struct megasas_instance { · 6 unmodified lines
20512138
20522139 u16 max_num_sge;
20532140 u16 max_fw_cmds;
2141+ u16 max_mpt_cmds;
20542142 u16 max_mfi_cmds;
20552143 u16 max_scsi_cmds;
20562144 u16 ldio_threshold;
@@ -2065,6 +2153,7 @@ struct megasas_instance { · 8 unmodified lines
20652153 /* used to sync fire the cmd to fw */
20662154 spinlock_t hba_lock;
20672155 /* used to synch producer, consumer ptrs in dpc */
2156+ spinlock_t stream_lock;
20682157 spinlock_t completion_lock;
20692158 struct dma_pool *frame_dma_pool;
20702159 struct dma_pool *sense_dma_pool;
@@ -2087,6 +2176,11 @@ struct megasas_instance { · 16 unmodified lines
20872176 atomic_t fw_outstanding;
20882177 atomic_t ldio_outstanding;
20892178 atomic_t fw_reset_no_pci_access;
2179+ atomic_t ieee_sgl;
2180+ atomic_t prp_sgl;
2181+ atomic_t sge_holes_type1;
2182+ atomic_t sge_holes_type2;
2183+ atomic_t sge_holes_type3;
20902184
20912185 struct megasas_instance_template *instancet;
20922186 struct tasklet_struct isr_tasklet;
@@ -2142,6 +2236,13 @@ struct megasas_instance { · 49 unmodified lines
21422236 u8 is_rdpq;
21432237 bool dev_handle;
21442238 bool fw_sync_cache_support;
2239+ u32 mfi_frame_size;
2240+ bool is_ventura;
2241+ bool msix_combined;
2242+ u16 max_raid_mapsize;
2243+ /* preffered count to send as LDIO irrspective of FP capable.*/
2244+ u8 r1_ldio_hint_default;
2245+ u32 nvme_page_size;
21452246 };
21462247 struct MR_LD_VF_MAP {
21472248 u32 size;
@@ -2230,12 +2331,12 @@ struct megasas_instance_template { · 82 unmodified lines
22302331 u32 (*init_adapter)(struct megasas_instance *);
22312332 u32 (*build_and_issue_cmd) (struct megasas_instance *,
22322333 struct scsi_cmnd *);
2233− int (*issue_dcmd)(struct megasas_instance *instance,
2334+ void (*issue_dcmd)(struct megasas_instance *instance,
22342335 struct megasas_cmd *cmd);
22352336 };
22362337
2237−#define MEGASAS_IS_LOGICAL(scp) \
2238− ((scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1)
2338+#define MEGASAS_IS_LOGICAL(sdev) \
2339+ ((sdev->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1)
22392340
22402341 #define MEGASAS_DEV_INDEX(scp) \
22412342 (((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \
@@ -2346,7 +2447,7 @@ MR_BuildRaidContext(struct megasas_instance *instance, · 104 unmodified lines
23462447 struct IO_REQUEST_INFO *io_info,
23472448 struct RAID_CONTEXT *pRAID_Context,
23482449 struct MR_DRV_RAID_MAP_ALL *map, u8 **raidLUN);
2349−u8 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map);
2450+u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map);
23502451 struct MR_LD_RAID *MR_LdRaidGet(u32 ld, struct MR_DRV_RAID_MAP_ALL *map);
23512452 u16 MR_ArPdGet(u32 ar, u32 arm, struct MR_DRV_RAID_MAP_ALL *map);
23522453 u16 MR_LdSpanArrayGet(u32 ld, u32 span, struct MR_DRV_RAID_MAP_ALL *map);
@@ -2354,13 +2455,16 @@ __le16 MR_PdDevHandleGet(u32 pd, struct MR_DRV_RAID_MAP_ALL *map); · 1 unmodified line
23542455 u16 MR_GetLDTgtId(u32 ld, struct MR_DRV_RAID_MAP_ALL *map);
23552456
23562457 __le16 get_updated_dev_handle(struct megasas_instance *instance,
2357− struct LD_LOAD_BALANCE_INFO *lbInfo, struct IO_REQUEST_INFO *in_info);
2458+ struct LD_LOAD_BALANCE_INFO *lbInfo,
2459+ struct IO_REQUEST_INFO *in_info,
2460+ struct MR_DRV_RAID_MAP_ALL *drv_map);
23582461 void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *map,
23592462 struct LD_LOAD_BALANCE_INFO *lbInfo);
23602463 int megasas_get_ctrl_info(struct megasas_instance *instance);
23612464 /* PD sequence */
23622465 int
23632466 megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend);
2467+void megasas_set_dynamic_target_properties(struct scsi_device *sdev);
23642468 int megasas_set_crash_dump_params(struct megasas_instance *instance,
23652469 u8 crash_buf_state);
23662470 void megasas_free_host_crash_buffer(struct megasas_instance *instance);
@@ -2382,4 +2486,7 @@ void megasas_update_sdev_properties(struct scsi_device *sdev); · 15 unmodified lines
23822486 int megasas_reset_fusion(struct Scsi_Host *shost, int reason);
23832487 int megasas_task_abort_fusion(struct scsi_cmnd *scmd);
23842488 int megasas_reset_target_fusion(struct scsi_cmnd *scmd);
2489+u32 mega_mod64(u64 dividend, u32 divisor);
2490+int megasas_alloc_fusion_context(struct megasas_instance *instance);
2491+void megasas_free_fusion_context(struct megasas_instance *instance);
23852492 #endif /*LSI_MEGARAID_SAS_H */
drivers/scsi/megaraid/megaraid_sas_base.c+488−160
@@ -43,6 +43,7 @@ · 42 unmodified lines
4343 #include <linux/uio.h>
4444 #include <linux/slab.h>
4545 #include <linux/uaccess.h>
46+#include <asm/unaligned.h>
4647 #include <linux/fs.h>
4748 #include <linux/compat.h>
4849 #include <linux/blkdev.h>
@@ -116,8 +117,10 @@ static int megasas_ld_list_query(struct megasas_instance *instance, · 67 unmodified lines
116117 static int megasas_issue_init_mfi(struct megasas_instance *instance);
117118 static int megasas_register_aen(struct megasas_instance *instance,
118119 u32 seq_num, u32 class_locale_word);
119−static int
120−megasas_get_pd_info(struct megasas_instance *instance, u16 device_id);
120+static void megasas_get_pd_info(struct megasas_instance *instance,
121+ struct scsi_device *sdev);
122+static int megasas_get_target_prop(struct megasas_instance *instance,
123+ struct scsi_device *sdev);
121124 /*
122125 * PCI ID table for all supported controllers
123126 */
@@ -155,6 +158,12 @@ static struct pci_device_id megasas_pci_table[] = { · 31 unmodified lines
155158 /* Intruder 24 port*/
156159 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_52)},
157160 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_53)},
161+ /* VENTURA */
162+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA)},
163+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_HARPOON)},
164+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_TOMCAT)},
165+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA_4PORT)},
166+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER_4PORT)},
158167 {}
159168 };
160169
@@ -196,12 +205,12 @@ void megasas_fusion_ocr_wq(struct work_struct *work); · 35 unmodified lines
196205 static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance,
197206 int initial);
198207
199−int
208+void
200209 megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
201210 {
202211 instance->instancet->fire_cmd(instance,
203212 cmd->frame_phys_addr, 0, instance->reg_set);
204− return 0;
213+ return;
205214 }
206215
207216 /**
@@ -259,6 +268,8 @@ megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) · 51 unmodified lines
259268 cmd->scmd = NULL;
260269 cmd->frame_count = 0;
261270 cmd->flags = 0;
271+ memset(cmd->frame, 0, instance->mfi_frame_size);
272+ cmd->frame->io.context = cpu_to_le32(cmd->index);
262273 if (!fusion && reset_devices)
263274 cmd->frame->hdr.cmd = MFI_CMD_INVALID;
264275 list_add(&cmd->list, (&instance->cmd_pool)->next);
@@ -989,13 +1000,14 @@ megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) · 724 unmodified lines
9891000 frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS;
9901001 frame_hdr->flags |= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE);
9911002
992− if ((atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) ||
993− (instance->instancet->issue_dcmd(instance, cmd))) {
1003+ if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
9941004 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
9951005 __func__, __LINE__);
9961006 return DCMD_NOT_FIRED;
9971007 }
9981008
1009+ instance->instancet->issue_dcmd(instance, cmd);
1010+
9991011 return wait_and_poll(instance, cmd, instance->requestorId ?
10001012 MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS);
10011013 }
@@ -1017,13 +1029,14 @@ megasas_issue_blocked_cmd(struct megasas_instance *instance, · 15 unmodified lines
10171029 int ret = 0;
10181030 cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
10191031
1020− if ((atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) ||
1021− (instance->instancet->issue_dcmd(instance, cmd))) {
1032+ if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
10221033 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
10231034 __func__, __LINE__);
10241035 return DCMD_NOT_FIRED;
10251036 }
10261037
1038+ instance->instancet->issue_dcmd(instance, cmd);
1039+
10271040 if (timeout) {
10281041 ret = wait_event_timeout(instance->int_cmd_wait_q,
10291042 cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ);
@@ -1081,13 +1094,14 @@ megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, · 51 unmodified lines
10811094 cmd->sync_cmd = 1;
10821095 cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
10831096
1084− if ((atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) ||
1085− (instance->instancet->issue_dcmd(instance, cmd))) {
1097+ if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
10861098 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
10871099 __func__, __LINE__);
10881100 return DCMD_NOT_FIRED;
10891101 }
10901102
1103+ instance->instancet->issue_dcmd(instance, cmd);
1104+
10911105 if (timeout) {
10921106 ret = wait_event_timeout(instance->abort_cmd_wait_q,
10931107 cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ);
@@ -1273,7 +1287,7 @@ megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, · 179 unmodified lines
12731287 u16 flags = 0;
12741288 struct megasas_pthru_frame *pthru;
12751289
1276− is_logical = MEGASAS_IS_LOGICAL(scp);
1290+ is_logical = MEGASAS_IS_LOGICAL(scp->device);
12771291 device_id = MEGASAS_DEV_INDEX(scp);
12781292 pthru = (struct megasas_pthru_frame *)cmd->frame;
12791293
@@ -1513,11 +1527,11 @@ inline int megasas_cmd_type(struct scsi_cmnd *cmd) · 233 unmodified lines
15131527 case WRITE_6:
15141528 case READ_16:
15151529 case WRITE_16:
1516− ret = (MEGASAS_IS_LOGICAL(cmd)) ?
1530+ ret = (MEGASAS_IS_LOGICAL(cmd->device)) ?
15171531 READ_WRITE_LDIO : READ_WRITE_SYSPDIO;
15181532 break;
15191533 default:
1520− ret = (MEGASAS_IS_LOGICAL(cmd)) ?
1534+ ret = (MEGASAS_IS_LOGICAL(cmd->device)) ?
15211535 NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO;
15221536 }
15231537 return ret;
@@ -1537,7 +1551,7 @@ megasas_dump_pending_frames(struct megasas_instance *instance) · 13 unmodified lines
15371551 struct megasas_io_frame *ldio;
15381552 struct megasas_pthru_frame *pthru;
15391553 u32 sgcount;
1540− u32 max_cmd = instance->max_fw_cmds;
1554+ u16 max_cmd = instance->max_fw_cmds;
15411555
15421556 dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no);
15431557 dev_err(&instance->pdev->dev, "[%d]: Total OS Pending cmds : %d\n",instance->host->host_no,atomic_read(&instance->fw_outstanding));
@@ -1662,7 +1676,7 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) · 118 unmodified lines
16621676 /* Check for an mpio path and adjust behavior */
16631677 if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) {
16641678 if (megasas_check_mpio_paths(instance, scmd) ==
1665− (DID_RESET << 16)) {
1679+ (DID_REQUEUE << 16)) {
16661680 return SCSI_MLQUEUE_HOST_BUSY;
16671681 } else {
16681682 scmd->result = DID_NO_CONNECT << 16;
@@ -1693,15 +1707,16 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) · 24 unmodified lines
16931707
16941708 scmd->result = 0;
16951709
1696− if (MEGASAS_IS_LOGICAL(scmd) &&
1710+ if (MEGASAS_IS_LOGICAL(scmd->device) &&
16971711 (scmd->device->id >= instance->fw_supported_vd_count ||
16981712 scmd->device->lun)) {
16991713 scmd->result = DID_BAD_TARGET << 16;
17001714 goto out_done;
17011715 }
17021716
1703− if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && MEGASAS_IS_LOGICAL(scmd) &&
1704− (!instance->fw_sync_cache_support)) {
1717+ if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) &&
1718+ MEGASAS_IS_LOGICAL(scmd->device) &&
1719+ (!instance->fw_sync_cache_support)) {
17051720 scmd->result = DID_OK << 16;
17061721 goto out_done;
17071722 }
@@ -1728,16 +1743,21 @@ static struct megasas_instance *megasas_lookup_instance(u16 host_no) · 20 unmodified lines
17281743 }
17291744
17301745 /*
1731−* megasas_update_sdev_properties - Update sdev structure based on controller's FW capabilities
1746+* megasas_set_dynamic_target_properties -
1747+* Device property set by driver may not be static and it is required to be
1748+* updated after OCR
1749+*
1750+* set tm_capable.
1751+* set dma alignment (only for eedp protection enable vd).
17321752 *
17331753 * @sdev: OS provided scsi device
17341754 *
17351755 * Returns void
17361756 */
1737−void megasas_update_sdev_properties(struct scsi_device *sdev)
1757+void megasas_set_dynamic_target_properties(struct scsi_device *sdev)
17381758 {
1739− u16 pd_index = 0;
1740− u32 device_id, ld;
1759+ u16 pd_index = 0, ld;
1760+ u32 device_id;
17411761 struct megasas_instance *instance;
17421762 struct fusion_context *fusion;
17431763 struct MR_PRIV_DEVICE *mr_device_priv_data;
@@ -1749,67 +1769,129 @@ void megasas_update_sdev_properties(struct scsi_device *sdev) · 5 unmodified lines
17491769 fusion = instance->ctrl_context;
17501770 mr_device_priv_data = sdev->hostdata;
17511771
1752− if (!fusion)
1772+ if (!fusion || !mr_device_priv_data)
17531773 return;
17541774
1755− if (sdev->channel < MEGASAS_MAX_PD_CHANNELS &&
1756− instance->use_seqnum_jbod_fp) {
1757− pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
1758− sdev->id;
1759− pd_sync = (void *)fusion->pd_seq_sync
1760− [(instance->pd_seq_map_id - 1) & 1];
1761− mr_device_priv_data->is_tm_capable =
1762− pd_sync->seq[pd_index].capability.tmCapable;
1763− } else {
1775+ if (MEGASAS_IS_LOGICAL(sdev)) {
17641776 device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL)
17651777 + sdev->id;
17661778 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
17671779 ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
1780+ if (ld >= instance->fw_supported_vd_count)
1781+ return;
17681782 raid = MR_LdRaidGet(ld, local_map_ptr);
17691783
17701784 if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER)
17711785 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1786+
17721787 mr_device_priv_data->is_tm_capable =
17731788 raid->capability.tmCapable;
1789+ } else if (instance->use_seqnum_jbod_fp) {
1790+ pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
1791+ sdev->id;
1792+ pd_sync = (void *)fusion->pd_seq_sync
1793+ [(instance->pd_seq_map_id - 1) & 1];
1794+ mr_device_priv_data->is_tm_capable =
1795+ pd_sync->seq[pd_index].capability.tmCapable;
17741796 }
17751797 }
17761798
1777−static void megasas_set_device_queue_depth(struct scsi_device *sdev)
1799+/*
1800+ * megasas_set_nvme_device_properties -
1801+ * set nomerges=2
1802+ * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K).
1803+ * set maximum io transfer = MDTS of NVME device provided by MR firmware.
1804+ *
1805+ * MR firmware provides value in KB. Caller of this function converts
1806+ * kb into bytes.
1807+ *
1808+ * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size,
1809+ * MR firmware provides value 128 as (32 * 4K) = 128K.
1810+ *
1811+ * @sdev: scsi device
1812+ * @max_io_size: maximum io transfer size
1813+ *
1814+ */
1815+static inline void
1816+megasas_set_nvme_device_properties(struct scsi_device *sdev, u32 max_io_size)
17781817 {
1779− u16 pd_index = 0;
1780− int ret = DCMD_FAILED;
17811818 struct megasas_instance *instance;
1819+ u32 mr_nvme_pg_size;
17821820
1783− instance = megasas_lookup_instance(sdev->host->host_no);
1821+ instance = (struct megasas_instance *)sdev->host->hostdata;
1822+ mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
1823+ MR_DEFAULT_NVME_PAGE_SIZE);
17841824
1785− if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
1786− pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id;
1825+ blk_queue_max_hw_sectors(sdev->request_queue, (max_io_size / 512));
17871826
1788− if (instance->pd_info) {
1789− mutex_lock(&instance->hba_mutex);
1790− ret = megasas_get_pd_info(instance, pd_index);
1791− mutex_unlock(&instance->hba_mutex);
1792− }
1827+ queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue);
1828+ blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1);
1829+}
17931830
1794− if (ret != DCMD_SUCCESS)
1795− return;
17961831
1797− if (instance->pd_list[pd_index].driveState == MR_PD_STATE_SYSTEM) {
1832+/*
1833+ * megasas_set_static_target_properties -
1834+ * Device property set by driver are static and it is not required to be
1835+ * updated after OCR.
1836+ *
1837+ * set io timeout
1838+ * set device queue depth
1839+ * set nvme device properties. see - megasas_set_nvme_device_properties
1840+ *
1841+ * @sdev: scsi device
1842+ * @is_target_prop true, if fw provided target properties.
1843+ */
1844+static void megasas_set_static_target_properties(struct scsi_device *sdev,
1845+ bool is_target_prop)
1846+{
1847+ u16 target_index = 0;
1848+ u8 interface_type;
1849+ u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN;
1850+ u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB;
1851+ u32 tgt_device_qd;
1852+ struct megasas_instance *instance;
1853+ struct MR_PRIV_DEVICE *mr_device_priv_data;
17981854
1799− switch (instance->pd_list[pd_index].interface) {
1800− case SAS_PD:
1801− scsi_change_queue_depth(sdev, MEGASAS_SAS_QD);
1802− break;
1855+ instance = megasas_lookup_instance(sdev->host->host_no);
1856+ mr_device_priv_data = sdev->hostdata;
1857+ interface_type = mr_device_priv_data->interface_type;
18031858
1804− case SATA_PD:
1805− scsi_change_queue_depth(sdev, MEGASAS_SATA_QD);
1806− break;
1859+ /*
1860+ * The RAID firmware may require extended timeouts.
1861+ */
1862+ blk_queue_rq_timeout(sdev->request_queue, scmd_timeout * HZ);
18071863
1808− default:
1809− scsi_change_queue_depth(sdev, MEGASAS_DEFAULT_PD_QD);
1810− }
1811− }
1864+ target_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id;
1865+
1866+ switch (interface_type) {
1867+ case SAS_PD:
1868+ device_qd = MEGASAS_SAS_QD;
1869+ break;
1870+ case SATA_PD:
1871+ device_qd = MEGASAS_SATA_QD;
1872+ break;
1873+ case NVME_PD:
1874+ device_qd = MEGASAS_NVME_QD;
1875+ break;
1876+ }
1877+
1878+ if (is_target_prop) {
1879+ tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth);
1880+ if (tgt_device_qd &&
1881+ (tgt_device_qd <= instance->host->can_queue))
1882+ device_qd = tgt_device_qd;
1883+
1884+ /* max_io_size_kb will be set to non zero for
1885+ * nvme based vd and syspd.
1886+ */
1887+ max_io_size_kb = le32_to_cpu(instance->tgt_prop->max_io_size_kb);
18121888 }
1889+
1890+ if (instance->nvme_page_size && max_io_size_kb)
1891+ megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 10));
1892+
1893+ scsi_change_queue_depth(sdev, device_qd);
1894+
18131895 }
18141896
18151897
@@ -1817,11 +1899,12 @@ static int megasas_slave_configure(struct scsi_device *sdev) · 1 unmodified line
18171899 {
18181900 u16 pd_index = 0;
18191901 struct megasas_instance *instance;
1902+ int ret_target_prop = DCMD_FAILED;
1903+ bool is_target_prop = false;
18201904
18211905 instance = megasas_lookup_instance(sdev->host->host_no);
18221906 if (instance->pd_list_not_supported) {
1823− if (sdev->channel < MEGASAS_MAX_PD_CHANNELS &&
1824− sdev->type == TYPE_DISK) {
1907+ if (!MEGASAS_IS_LOGICAL(sdev) && sdev->type == TYPE_DISK) {
18251908 pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
18261909 sdev->id;
18271910 if (instance->pd_list[pd_index].driveState !=
@@ -1829,14 +1912,25 @@ static int megasas_slave_configure(struct scsi_device *sdev) · 1 unmodified line
18291912 return -ENXIO;
18301913 }
18311914 }
1832− megasas_set_device_queue_depth(sdev);
1833− megasas_update_sdev_properties(sdev);
18341915
1835− /*
1836− * The RAID firmware may require extended timeouts.
1916+ mutex_lock(&instance->hba_mutex);
1917+ /* Send DCMD to Firmware and cache the information */
1918+ if ((instance->pd_info) && !MEGASAS_IS_LOGICAL(sdev))
1919+ megasas_get_pd_info(instance, sdev);
1920+
1921+ /* Some ventura firmware may not have instance->nvme_page_size set.
1922+ * Do not send MR_DCMD_DRV_GET_TARGET_PROP
18371923 */
1838− blk_queue_rq_timeout(sdev->request_queue,
1839− scmd_timeout * HZ);
1924+ if ((instance->tgt_prop) && (instance->nvme_page_size))
1925+ ret_target_prop = megasas_get_target_prop(instance, sdev);
1926+
1927+ is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false;
1928+ megasas_set_static_target_properties(sdev, is_target_prop);
1929+
1930+ mutex_unlock(&instance->hba_mutex);
1931+
1932+ /* This sdev property may change post OCR */
1933+ megasas_set_dynamic_target_properties(sdev);
18401934
18411935 return 0;
18421936 }
@@ -1848,7 +1942,7 @@ static int megasas_slave_alloc(struct scsi_device *sdev) · 5 unmodified lines
18481942 struct MR_PRIV_DEVICE *mr_device_priv_data;
18491943
18501944 instance = megasas_lookup_instance(sdev->host->host_no);
1851− if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
1945+ if (!MEGASAS_IS_LOGICAL(sdev)) {
18521946 /*
18531947 * Open the OS scan to the SYSTEM PD
18541948 */
@@ -2483,7 +2577,7 @@ static int megasas_wait_for_outstanding(struct megasas_instance *instance) · 628 unmodified lines
24832577 struct megasas_cmd, list);
24842578 list_del_init(&reset_cmd->list);
24852579 if (reset_cmd->scmd) {
2486− reset_cmd->scmd->result = DID_RESET << 16;
2580+ reset_cmd->scmd->result = DID_REQUEUE << 16;
24872581 dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n",
24882582 reset_index, reset_cmd,
24892583 reset_cmd->scmd->cmnd[0]);
@@ -2650,6 +2744,24 @@ blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) · 160 unmodified lines
26502744 return BLK_EH_RESET_TIMER;
26512745 }
26522746
2747+/**
2748+ * megasas_dump_frame - This function will dump MPT/MFI frame
2749+ */
2750+static inline void
2751+megasas_dump_frame(void *mpi_request, int sz)
2752+{
2753+ int i;
2754+ __le32 *mfp = (__le32 *)mpi_request;
2755+
2756+ printk(KERN_INFO "IO request frame:\n\t");
2757+ for (i = 0; i < sz / sizeof(__le32); i++) {
2758+ if (i && ((i % 8) == 0))
2759+ printk("\n\t");
2760+ printk("%08x ", le32_to_cpu(mfp[i]));
2761+ }
2762+ printk("\n");
2763+}
2764+
26532765 /**
26542766 * megasas_reset_bus_host - Bus & host reset handler entry point
26552767 */
@@ -2660,12 +2772,26 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd) · 4 unmodified lines
26602772
26612773 instance = (struct megasas_instance *)scmd->device->host->hostdata;
26622774
2775+ scmd_printk(KERN_INFO, scmd,
2776+ "Controller reset is requested due to IO timeout\n"
2777+ "SCSI command pointer: (%p)\t SCSI host state: %d\t"
2778+ " SCSI host busy: %d\t FW outstanding: %d\n",
2779+ scmd, scmd->device->host->shost_state,
2780+ atomic_read((atomic_t *)&scmd->device->host->host_busy),
2781+ atomic_read(&instance->fw_outstanding));
2782+
26632783 /*
26642784 * First wait for all commands to complete
26652785 */
2666− if (instance->ctrl_context)
2667− ret = megasas_reset_fusion(scmd->device->host, 1);
2668− else
2786+ if (instance->ctrl_context) {
2787+ struct megasas_cmd_fusion *cmd;
2788+ cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr;
2789+ if (cmd)
2790+ megasas_dump_frame(cmd->io_request,
2791+ sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
2792+ ret = megasas_reset_fusion(scmd->device->host,
2793+ SCSIIO_TIMEOUT_OCR);
2794+ } else
26692795 ret = megasas_generic_reset(scmd);
26702796
26712797 return ret;
@@ -3343,7 +3469,7 @@ megasas_internal_reset_defer_cmds(struct megasas_instance *instance) · 671 unmodified lines
33433469 {
33443470 struct megasas_cmd *cmd;
33453471 int i;
3346− u32 max_cmd = instance->max_fw_cmds;
3472+ u16 max_cmd = instance->max_fw_cmds;
33473473 u32 defer_index;
33483474 unsigned long flags;
33493475
@@ -3719,7 +3845,7 @@ megasas_transition_to_ready(struct megasas_instance *instance, int ocr) · 369 unmodified lines
37193845 static void megasas_teardown_frame_pool(struct megasas_instance *instance)
37203846 {
37213847 int i;
3722− u32 max_cmd = instance->max_mfi_cmds;
3848+ u16 max_cmd = instance->max_mfi_cmds;
37233849 struct megasas_cmd *cmd;
37243850
37253851 if (!instance->frame_dma_pool)
@@ -3763,9 +3889,8 @@ static void megasas_teardown_frame_pool(struct megasas_instance *instance) · 37 unmodified lines
37633889 static int megasas_create_frame_pool(struct megasas_instance *instance)
37643890 {
37653891 int i;
3766− u32 max_cmd;
3892+ u16 max_cmd;
37673893 u32 sge_sz;
3768− u32 total_sz;
37693894 u32 frame_count;
37703895 struct megasas_cmd *cmd;
37713896
@@ -3793,12 +3918,13 @@ static int megasas_create_frame_pool(struct megasas_instance *instance) · 21 unmodified lines
37933918 * Total 192 byte (3 MFI frame of 64 byte)
37943919 */
37953920 frame_count = instance->ctrl_context ? (3 + 1) : (15 + 1);
3796− total_sz = MEGAMFI_FRAME_SIZE * frame_count;
3921+ instance->mfi_frame_size = MEGAMFI_FRAME_SIZE * frame_count;
37973922 /*
37983923 * Use DMA pool facility provided by PCI layer
37993924 */
38003925 instance->frame_dma_pool = pci_pool_create("megasas frame pool",
3801− instance->pdev, total_sz, 256, 0);
3926+ instance->pdev, instance->mfi_frame_size,
3927+ 256, 0);
38023928
38033929 if (!instance->frame_dma_pool) {
38043930 dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup frame pool\n");
@@ -3842,7 +3968,7 @@ static int megasas_create_frame_pool(struct megasas_instance *instance) · 37 unmodified lines
38423968 return -ENOMEM;
38433969 }
38443970
3845− memset(cmd->frame, 0, total_sz);
3971+ memset(cmd->frame, 0, instance->mfi_frame_size);
38463972 cmd->frame->io.context = cpu_to_le32(cmd->index);
38473973 cmd->frame->io.pad_0 = 0;
38483974 if (!instance->ctrl_context && reset_devices)
@@ -3897,7 +4023,7 @@ int megasas_alloc_cmds(struct megasas_instance *instance) · 48 unmodified lines
38974023 {
38984024 int i;
38994025 int j;
3900− u32 max_cmd;
4026+ u16 max_cmd;
39014027 struct megasas_cmd *cmd;
39024028 struct fusion_context *fusion;
39034029
@@ -3974,18 +4100,22 @@ dcmd_timeout_ocr_possible(struct megasas_instance *instance) { · 70 unmodified lines
39744100 return INITIATE_OCR;
39754101 }
39764102
3977−static int
3978−megasas_get_pd_info(struct megasas_instance *instance, u16 device_id)
4103+static void
4104+megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev)
39794105 {
39804106 int ret;
39814107 struct megasas_cmd *cmd;
39824108 struct megasas_dcmd_frame *dcmd;
39834109
4110+ struct MR_PRIV_DEVICE *mr_device_priv_data;
4111+ u16 device_id = 0;
4112+
4113+ device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id;
39844114 cmd = megasas_get_cmd(instance);
39854115
39864116 if (!cmd) {
39874117 dev_err(&instance->pdev->dev, "Failed to get cmd %s\n", __func__);
3988− return -ENOMEM;
4118+ return;
39894119 }
39904120
39914121 dcmd = &cmd->frame->dcmd;
@@ -4012,7 +4142,9 @@ megasas_get_pd_info(struct megasas_instance *instance, u16 device_id) · 20 unmodified lines
40124142
40134143 switch (ret) {
40144144 case DCMD_SUCCESS:
4015− instance->pd_list[device_id].interface =
4145+ mr_device_priv_data = sdev->hostdata;
4146+ le16_to_cpus((u16 *)&instance->pd_info->state.ddf.pdType);
4147+ mr_device_priv_data->interface_type =
40164148 instance->pd_info->state.ddf.pdType.intf;
40174149 break;
40184150
@@ -4039,7 +4171,7 @@ megasas_get_pd_info(struct megasas_instance *instance, u16 device_id) · 20 unmodified lines
40394171 if (ret != DCMD_TIMEOUT)
40404172 megasas_return_cmd(instance, cmd);
40414173
4042− return ret;
4174+ return;
40434175 }
40444176 /*
40454177 * megasas_get_pd_list_info - Returns FW's pd_list structure
@@ -4418,8 +4550,7 @@ megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) · 372 unmodified lines
44184550 static void megasas_update_ext_vd_details(struct megasas_instance *instance)
44194551 {
44204552 struct fusion_context *fusion;
4421− u32 old_map_sz;
4422− u32 new_map_sz;
4553+ u32 ventura_map_sz = 0;
44234554
44244555 fusion = instance->ctrl_context;
44254556 /* For MFI based controllers return dummy success */
@@ -4449,21 +4580,27 @@ static void megasas_update_ext_vd_details(struct megasas_instance *instance) · 23 unmodified lines
44494580 instance->supportmax256vd ? "Extended VD(240 VD)firmware" :
44504581 "Legacy(64 VD) firmware");
44514582
4452− old_map_sz = sizeof(struct MR_FW_RAID_MAP) +
4453− (sizeof(struct MR_LD_SPAN_MAP) *
4454− (instance->fw_supported_vd_count - 1));
4455− new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT);
4456− fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP) +
4457− (sizeof(struct MR_LD_SPAN_MAP) *
4458− (instance->drv_supported_vd_count - 1));
4459−
4460− fusion->max_map_sz = max(old_map_sz, new_map_sz);
4583+ if (instance->max_raid_mapsize) {
4584+ ventura_map_sz = instance->max_raid_mapsize *
4585+ MR_MIN_MAP_SIZE; /* 64k */
4586+ fusion->current_map_sz = ventura_map_sz;
4587+ fusion->max_map_sz = ventura_map_sz;
4588+ } else {
4589+ fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) +
4590+ (sizeof(struct MR_LD_SPAN_MAP) *
4591+ (instance->fw_supported_vd_count - 1));
4592+ fusion->new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT);
44614593
4594+ fusion->max_map_sz =
4595+ max(fusion->old_map_sz, fusion->new_map_sz);
44624596
4463− if (instance->supportmax256vd)
4464− fusion->current_map_sz = new_map_sz;
4465− else
4466− fusion->current_map_sz = old_map_sz;
4597+ if (instance->supportmax256vd)
4598+ fusion->current_map_sz = fusion->new_map_sz;
4599+ else
4600+ fusion->current_map_sz = fusion->old_map_sz;
4601+ }
4602+ /* irrespective of FW raid maps, driver raid map is constant */
4603+ fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP_ALL);
44674604 }
44684605
44694606 /**
@@ -4533,6 +4670,7 @@ megasas_get_ctrl_info(struct megasas_instance *instance) · 63 unmodified lines
45334670 le32_to_cpus((u32 *)&ctrl_info->properties.OnOffProperties);
45344671 le32_to_cpus((u32 *)&ctrl_info->adapterOperations2);
45354672 le32_to_cpus((u32 *)&ctrl_info->adapterOperations3);
4673+ le16_to_cpus((u16 *)&ctrl_info->adapter_operations4);
45364674
45374675 /* Update the latest Ext VD info.
45384676 * From Init path, store current firmware details.
@@ -4542,6 +4680,8 @@ megasas_get_ctrl_info(struct megasas_instance *instance) · 3 unmodified lines
45424680 megasas_update_ext_vd_details(instance);
45434681 instance->use_seqnum_jbod_fp =
45444682 ctrl_info->adapterOperations3.useSeqNumJbodFP;
4683+ instance->support_morethan256jbod =
4684+ ctrl_info->adapter_operations4.support_pd_map_target_id;
45454685
45464686 /*Check whether controller is iMR or MR */
45474687 instance->is_imr = (ctrl_info->memory_size ? 0 : 1);
@@ -4989,13 +5129,13 @@ skip_alloc: · 441 unmodified lines
49895129 static int megasas_init_fw(struct megasas_instance *instance)
49905130 {
49915131 u32 max_sectors_1;
4992− u32 max_sectors_2;
4993− u32 tmp_sectors, msix_enable, scratch_pad_2;
5132+ u32 max_sectors_2, tmp_sectors, msix_enable;
5133+ u32 scratch_pad_2, scratch_pad_3, scratch_pad_4;
49945134 resource_size_t base_addr;
49955135 struct megasas_register_set __iomem *reg_set;
49965136 struct megasas_ctrl_info *ctrl_info = NULL;
49975137 unsigned long bar_list;
4998− int i, loop, fw_msix_count = 0;
5138+ int i, j, loop, fw_msix_count = 0;
49995139 struct IOV_111 *iovPtr;
50005140 struct fusion_context *fusion;
50015141
@@ -5020,34 +5160,29 @@ static int megasas_init_fw(struct megasas_instance *instance) · 18 unmodified lines
50205160
50215161 reg_set = instance->reg_set;
50225162
5023− switch (instance->pdev->device) {
5024− case PCI_DEVICE_ID_LSI_FUSION:
5025− case PCI_DEVICE_ID_LSI_PLASMA:
5026− case PCI_DEVICE_ID_LSI_INVADER:
5027− case PCI_DEVICE_ID_LSI_FURY:
5028− case PCI_DEVICE_ID_LSI_INTRUDER:
5029− case PCI_DEVICE_ID_LSI_INTRUDER_24:
5030− case PCI_DEVICE_ID_LSI_CUTLASS_52:
5031− case PCI_DEVICE_ID_LSI_CUTLASS_53:
5163+ if (fusion)
50325164 instance->instancet = &megasas_instance_template_fusion;
5033− break;
5034− case PCI_DEVICE_ID_LSI_SAS1078R:
5035− case PCI_DEVICE_ID_LSI_SAS1078DE:
5036− instance->instancet = &megasas_instance_template_ppc;
5037− break;
5038− case PCI_DEVICE_ID_LSI_SAS1078GEN2:
5039− case PCI_DEVICE_ID_LSI_SAS0079GEN2:
5040− instance->instancet = &megasas_instance_template_gen2;
5041− break;
5042− case PCI_DEVICE_ID_LSI_SAS0073SKINNY:
5043− case PCI_DEVICE_ID_LSI_SAS0071SKINNY:
5044− instance->instancet = &megasas_instance_template_skinny;
5045− break;
5046− case PCI_DEVICE_ID_LSI_SAS1064R:
5047− case PCI_DEVICE_ID_DELL_PERC5:
5048− default:
5049− instance->instancet = &megasas_instance_template_xscale;
5050− break;
5165+ else {
5166+ switch (instance->pdev->device) {
5167+ case PCI_DEVICE_ID_LSI_SAS1078R:
5168+ case PCI_DEVICE_ID_LSI_SAS1078DE:
5169+ instance->instancet = &megasas_instance_template_ppc;
5170+ break;
5171+ case PCI_DEVICE_ID_LSI_SAS1078GEN2:
5172+ case PCI_DEVICE_ID_LSI_SAS0079GEN2:
5173+ instance->instancet = &megasas_instance_template_gen2;
5174+ break;
5175+ case PCI_DEVICE_ID_LSI_SAS0073SKINNY:
5176+ case PCI_DEVICE_ID_LSI_SAS0071SKINNY:
5177+ instance->instancet = &megasas_instance_template_skinny;
5178+ break;
5179+ case PCI_DEVICE_ID_LSI_SAS1064R:
5180+ case PCI_DEVICE_ID_DELL_PERC5:
5181+ default:
5182+ instance->instancet = &megasas_instance_template_xscale;
5183+ instance->pd_list_not_supported = 1;
5184+ break;
5185+ }
50515186 }
50525187
50535188 if (megasas_transition_to_ready(instance, 0)) {
@@ -5066,13 +5201,13 @@ static int megasas_init_fw(struct megasas_instance *instance) · 12 unmodified lines
50665201 goto fail_ready_state;
50675202 }
50685203
5069− /*
5070− * MSI-X host index 0 is common for all adapter.
5071− * It is used for all MPT based Adapters.
5072− */
5073− instance->reply_post_host_index_addr[0] =
5074− (u32 __iomem *)((u8 __iomem *)instance->reg_set +
5075− MPI2_REPLY_POST_HOST_INDEX_OFFSET);
5204+ if (instance->is_ventura) {
5205+ scratch_pad_3 =
5206+ readl(&instance->reg_set->outbound_scratch_pad_3);
5207+ instance->max_raid_mapsize = ((scratch_pad_3 >>
5208+ MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) &
5209+ MR_MAX_RAID_MAP_SIZE_MASK);
5210+ }
50765211
50775212 /* Check if MSI-X is supported while in ready state */
50785213 msix_enable = (instance->instancet->read_fw_status_reg(reg_set) &
@@ -5092,6 +5227,9 @@ static int megasas_init_fw(struct megasas_instance *instance) · 13 unmodified lines
50925227 instance->msix_vectors = ((scratch_pad_2
50935228 & MR_MAX_REPLY_QUEUES_EXT_OFFSET)
50945229 >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1;
5230+ if (instance->msix_vectors > 16)
5231+ instance->msix_combined = true;
5232+
50955233 if (rdpq_enable)
50965234 instance->is_rdpq = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ?
50975235 1 : 0;
@@ -5125,6 +5263,20 @@ static int megasas_init_fw(struct megasas_instance *instance) · 27 unmodified lines
51255263 else
51265264 instance->msix_vectors = 0;
51275265 }
5266+ /*
5267+ * MSI-X host index 0 is common for all adapter.
5268+ * It is used for all MPT based Adapters.
5269+ */
5270+ if (instance->msix_combined) {
5271+ instance->reply_post_host_index_addr[0] =
5272+ (u32 *)((u8 *)instance->reg_set +
5273+ MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET);
5274+ } else {
5275+ instance->reply_post_host_index_addr[0] =
5276+ (u32 *)((u8 *)instance->reg_set +
5277+ MPI2_REPLY_POST_HOST_INDEX_OFFSET);
5278+ }
5279+
51285280 i = pci_alloc_irq_vectors(instance->pdev, 1, 1, PCI_IRQ_LEGACY);
51295281 if (i < 0)
51305282 goto fail_setup_irqs;
@@ -5155,6 +5307,18 @@ static int megasas_init_fw(struct megasas_instance *instance) · 24 unmodified lines
51555307 if (instance->instancet->init_adapter(instance))
51565308 goto fail_init_adapter;
51575309
5310+ if (instance->is_ventura) {
5311+ scratch_pad_4 =
5312+ readl(&instance->reg_set->outbound_scratch_pad_4);
5313+ if ((scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK) >=
5314+ MR_DEFAULT_NVME_PAGE_SHIFT)
5315+ instance->nvme_page_size =
5316+ (1 << (scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK));
5317+
5318+ dev_info(&instance->pdev->dev,
5319+ "NVME page size\t: (%d)\n", instance->nvme_page_size);
5320+ }
5321+
51585322 if (instance->msix_vectors ?
51595323 megasas_setup_irqs_msix(instance, 1) :
51605324 megasas_setup_irqs_ioapic(instance))
@@ -5173,13 +5337,43 @@ static int megasas_init_fw(struct megasas_instance *instance) · 12 unmodified lines
51735337 (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)));
51745338 if (megasas_get_pd_list(instance) < 0) {
51755339 dev_err(&instance->pdev->dev, "failed to get PD list\n");
5176− goto fail_get_pd_list;
5340+ goto fail_get_ld_pd_list;
51775341 }
51785342
51795343 memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
5344+
5345+ /* stream detection initialization */
5346+ if (instance->is_ventura && fusion) {
5347+ fusion->stream_detect_by_ld =
5348+ kzalloc(sizeof(struct LD_STREAM_DETECT *)
5349+ * MAX_LOGICAL_DRIVES_EXT,
5350+ GFP_KERNEL);
5351+ if (!fusion->stream_detect_by_ld) {
5352+ dev_err(&instance->pdev->dev,
5353+ "unable to allocate stream detection for pool of LDs\n");
5354+ goto fail_get_ld_pd_list;
5355+ }
5356+ for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) {
5357+ fusion->stream_detect_by_ld[i] =
5358+ kmalloc(sizeof(struct LD_STREAM_DETECT),
5359+ GFP_KERNEL);
5360+ if (!fusion->stream_detect_by_ld[i]) {
5361+ dev_err(&instance->pdev->dev,
5362+ "unable to allocate stream detect by LD\n ");
5363+ for (j = 0; j < i; ++j)
5364+ kfree(fusion->stream_detect_by_ld[j]);
5365+ kfree(fusion->stream_detect_by_ld);
5366+ fusion->stream_detect_by_ld = NULL;
5367+ goto fail_get_ld_pd_list;
5368+ }
5369+ fusion->stream_detect_by_ld[i]->mru_bit_map
5370+ = MR_STREAM_BITMAP;
5371+ }
5372+ }
5373+
51805374 if (megasas_ld_list_query(instance,
51815375 MR_LD_QUERY_TYPE_EXPOSED_TO_HOST))
5182− megasas_get_ld_list(instance);
5376+ goto fail_get_ld_pd_list;
51835377
51845378 /*
51855379 * Compute the max allowed sectors per IO: The controller info has two
@@ -5296,7 +5490,7 @@ static int megasas_init_fw(struct megasas_instance *instance) · 110 unmodified lines
52965490
52975491 return 0;
52985492
5299−fail_get_pd_list:
5493+fail_get_ld_pd_list:
53005494 instance->instancet->disable_intr(instance);
53015495 fail_init_adapter:
53025496 megasas_destroy_irqs(instance);
@@ -5309,9 +5503,11 @@ fail_ready_state: · 6 unmodified lines
53095503 instance->ctrl_info = NULL;
53105504 iounmap(instance->reg_set);
53115505
5312− fail_ioremap:
5506+fail_ioremap:
53135507 pci_release_selected_regions(instance->pdev, 1<<instance->bar);
53145508
5509+ dev_err(&instance->pdev->dev, "Failed from %s %d\n",
5510+ __func__, __LINE__);
53155511 return -EINVAL;
53165512 }
53175513
@@ -5531,6 +5727,98 @@ megasas_register_aen(struct megasas_instance *instance, u32 seq_num, · 213 unmodified lines
55315727 return 0;
55325728 }
55335729
5730+/* megasas_get_target_prop - Send DCMD with below details to firmware.
5731+ *
5732+ * This DCMD will fetch few properties of LD/system PD defined
5733+ * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value.
5734+ *
5735+ * DCMD send by drivers whenever new target is added to the OS.
5736+ *
5737+ * dcmd.opcode - MR_DCMD_DEV_GET_TARGET_PROP
5738+ * dcmd.mbox.b[0] - DCMD is to be fired for LD or system PD.
5739+ * 0 = system PD, 1 = LD.
5740+ * dcmd.mbox.s[1] - TargetID for LD/system PD.
5741+ * dcmd.sge IN - Pointer to return MR_TARGET_DEV_PROPERTIES.
5742+ *
5743+ * @instance: Adapter soft state
5744+ * @sdev: OS provided scsi device
5745+ *
5746+ * Returns 0 on success non-zero on failure.
5747+ */
5748+static int
5749+megasas_get_target_prop(struct megasas_instance *instance,
5750+ struct scsi_device *sdev)
5751+{
5752+ int ret;
5753+ struct megasas_cmd *cmd;
5754+ struct megasas_dcmd_frame *dcmd;
5755+ u16 targetId = (sdev->channel % 2) + sdev->id;
5756+
5757+ cmd = megasas_get_cmd(instance);
5758+
5759+ if (!cmd) {
5760+ dev_err(&instance->pdev->dev,
5761+ "Failed to get cmd %s\n", __func__);
5762+ return -ENOMEM;
5763+ }
5764+
5765+ dcmd = &cmd->frame->dcmd;
5766+
5767+ memset(instance->tgt_prop, 0, sizeof(*instance->tgt_prop));
5768+ memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
5769+ dcmd->mbox.b[0] = MEGASAS_IS_LOGICAL(sdev);
5770+
5771+ dcmd->mbox.s[1] = cpu_to_le16(targetId);
5772+ dcmd->cmd = MFI_CMD_DCMD;
5773+ dcmd->cmd_status = 0xFF;
5774+ dcmd->sge_count = 1;
5775+ dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
5776+ dcmd->timeout = 0;
5777+ dcmd->pad_0 = 0;
5778+ dcmd->data_xfer_len =
5779+ cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES));
5780+ dcmd->opcode = cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP);
5781+ dcmd->sgl.sge32[0].phys_addr =
5782+ cpu_to_le32(instance->tgt_prop_h);
5783+ dcmd->sgl.sge32[0].length =
5784+ cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES));
5785+
5786+ if (instance->ctrl_context && !instance->mask_interrupts)
5787+ ret = megasas_issue_blocked_cmd(instance,
5788+ cmd, MFI_IO_TIMEOUT_SECS);
5789+ else
5790+ ret = megasas_issue_polled(instance, cmd);
5791+
5792+ switch (ret) {
5793+ case DCMD_TIMEOUT:
5794+ switch (dcmd_timeout_ocr_possible(instance)) {
5795+ case INITIATE_OCR:
5796+ cmd->flags |= DRV_DCMD_SKIP_REFIRE;
5797+ megasas_reset_fusion(instance->host,
5798+ MFI_IO_TIMEOUT_OCR);
5799+ break;
5800+ case KILL_ADAPTER:
5801+ megaraid_sas_kill_hba(instance);
5802+ break;
5803+ case IGNORE_TIMEOUT:
5804+ dev_info(&instance->pdev->dev,
5805+ "Ignore DCMD timeout: %s %d\n",
5806+ __func__, __LINE__);
5807+ break;
5808+ }
5809+ break;
5810+
5811+ default:
5812+ megasas_return_cmd(instance, cmd);
5813+ }
5814+ if (ret != DCMD_SUCCESS)
5815+ dev_err(&instance->pdev->dev,
5816+ "return from %s %d return value %d\n",
5817+ __func__, __LINE__, ret);
5818+
5819+ return ret;
5820+}
5821+
55345822 /**
55355823 * megasas_start_aen - Subscribes to AEN during driver load time
55365824 * @instance: Adapter soft state
@@ -5714,6 +6002,12 @@ static int megasas_probe_one(struct pci_dev *pdev, · 177 unmodified lines
57146002 instance->pdev = pdev;
57156003
57166004 switch (instance->pdev->device) {
6005+ case PCI_DEVICE_ID_LSI_VENTURA:
6006+ case PCI_DEVICE_ID_LSI_HARPOON:
6007+ case PCI_DEVICE_ID_LSI_TOMCAT:
6008+ case PCI_DEVICE_ID_LSI_VENTURA_4PORT:
6009+ case PCI_DEVICE_ID_LSI_CRUSADER_4PORT:
6010+ instance->is_ventura = true;
57176011 case PCI_DEVICE_ID_LSI_FUSION:
57186012 case PCI_DEVICE_ID_LSI_PLASMA:
57196013 case PCI_DEVICE_ID_LSI_INVADER:
@@ -5723,21 +6017,17 @@ static int megasas_probe_one(struct pci_dev *pdev, · 3 unmodified lines
57236017 case PCI_DEVICE_ID_LSI_CUTLASS_52:
57246018 case PCI_DEVICE_ID_LSI_CUTLASS_53:
57256019 {
5726− instance->ctrl_context_pages =
5727− get_order(sizeof(struct fusion_context));
5728− instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL,
5729− instance->ctrl_context_pages);
5730− if (!instance->ctrl_context) {
5731− dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate "
5732− "memory for Fusion context info\n");
6020+ if (megasas_alloc_fusion_context(instance)) {
6021+ megasas_free_fusion_context(instance);
57336022 goto fail_alloc_dma_buf;
57346023 }
57356024 fusion = instance->ctrl_context;
5736− memset(fusion, 0,
5737− ((1 << PAGE_SHIFT) << instance->ctrl_context_pages));
6025+
57386026 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
57396027 (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA))
57406028 fusion->adapter_type = THUNDERBOLT_SERIES;
6029+ else if (instance->is_ventura)
6030+ fusion->adapter_type = VENTURA_SERIES;
57416031 else
57426032 fusion->adapter_type = INVADER_SERIES;
57436033 }
@@ -5799,9 +6089,17 @@ static int megasas_probe_one(struct pci_dev *pdev, · 55 unmodified lines
57996089 instance->pd_info = pci_alloc_consistent(pdev,
58006090 sizeof(struct MR_PD_INFO), &instance->pd_info_h);
58016091
6092+ instance->pd_info = pci_alloc_consistent(pdev,
6093+ sizeof(struct MR_PD_INFO), &instance->pd_info_h);
6094+ instance->tgt_prop = pci_alloc_consistent(pdev,
6095+ sizeof(struct MR_TARGET_PROPERTIES), &instance->tgt_prop_h);
6096+
58026097 if (!instance->pd_info)
58036098 dev_err(&instance->pdev->dev, "Failed to alloc mem for pd_info\n");
58046099
6100+ if (!instance->tgt_prop)
6101+ dev_err(&instance->pdev->dev, "Failed to alloc mem for tgt_prop\n");
6102+
58056103 instance->crash_dump_buf = pci_alloc_consistent(pdev,
58066104 CRASH_DMA_BUF_SIZE,
58076105 &instance->crash_dump_h);
@@ -5823,6 +6121,7 @@ static int megasas_probe_one(struct pci_dev *pdev, · 15 unmodified lines
58236121
58246122 spin_lock_init(&instance->mfi_pool_lock);
58256123 spin_lock_init(&instance->hba_lock);
6124+ spin_lock_init(&instance->stream_lock);
58266125 spin_lock_init(&instance->completion_lock);
58276126
58286127 mutex_init(&instance->reset_mutex);
@@ -5945,6 +6244,10 @@ fail_alloc_dma_buf: · 116 unmodified lines
59456244 pci_free_consistent(pdev, sizeof(struct MR_PD_INFO),
59466245 instance->pd_info,
59476246 instance->pd_info_h);
6247+ if (instance->tgt_prop)
6248+ pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
6249+ instance->tgt_prop,
6250+ instance->tgt_prop_h);
59486251 if (instance->producer)
59496252 pci_free_consistent(pdev, sizeof(u32), instance->producer,
59506253 instance->producer_h);
@@ -6217,6 +6520,10 @@ fail_init_mfi: · 266 unmodified lines
62176520 pci_free_consistent(pdev, sizeof(struct MR_PD_INFO),
62186521 instance->pd_info,
62196522 instance->pd_info_h);
6523+ if (instance->tgt_prop)
6524+ pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
6525+ instance->tgt_prop,
6526+ instance->tgt_prop_h);
62206527 if (instance->producer)
62216528 pci_free_consistent(pdev, sizeof(u32), instance->producer,
62226529 instance->producer_h);
@@ -6330,6 +6637,14 @@ skip_firing_dcmds: · 107 unmodified lines
63306637 if (instance->msix_vectors)
63316638 pci_free_irq_vectors(instance->pdev);
63326639
6640+ if (instance->is_ventura) {
6641+ for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i)
6642+ kfree(fusion->stream_detect_by_ld[i]);
6643+ kfree(fusion->stream_detect_by_ld);
6644+ fusion->stream_detect_by_ld = NULL;
6645+ }
6646+
6647+
63336648 if (instance->ctrl_context) {
63346649 megasas_release_fusion(instance);
63356650 pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) +
@@ -6350,8 +6665,7 @@ skip_firing_dcmds: · 14 unmodified lines
63506665 fusion->pd_seq_sync[i],
63516666 fusion->pd_seq_phys[i]);
63526667 }
6353− free_pages((ulong)instance->ctrl_context,
6354− instance->ctrl_context_pages);
6668+ megasas_free_fusion_context(instance);
63556669 } else {
63566670 megasas_release_mfi(instance);
63576671 pci_free_consistent(pdev, sizeof(u32),
@@ -6367,11 +6681,14 @@ skip_firing_dcmds: · 9 unmodified lines
63676681 if (instance->evt_detail)
63686682 pci_free_consistent(pdev, sizeof(struct megasas_evt_detail),
63696683 instance->evt_detail, instance->evt_detail_h);
6370−
63716684 if (instance->pd_info)
63726685 pci_free_consistent(pdev, sizeof(struct MR_PD_INFO),
63736686 instance->pd_info,
63746687 instance->pd_info_h);
6688+ if (instance->tgt_prop)
6689+ pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
6690+ instance->tgt_prop,
6691+ instance->tgt_prop_h);
63756692 if (instance->vf_affiliation)
63766693 pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) *
63776694 sizeof(struct MR_LD_VF_AFFILIATION),
@@ -6570,6 +6887,13 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · 192 unmodified lines
65706887 MFI_FRAME_SGL64 |
65716888 MFI_FRAME_SENSE64));
65726889
6890+ if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_SHUTDOWN) {
6891+ if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) {
6892+ megasas_return_cmd(instance, cmd);
6893+ return -1;
6894+ }
6895+ }
6896+
65736897 if (cmd->frame->dcmd.opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) {
65746898 error = megasas_set_crash_dump_params_ioctl(cmd);
65756899 megasas_return_cmd(instance, cmd);
@@ -6678,7 +7002,8 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · 102 unmodified lines
66787002 sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw +
66797003 ioc->sense_off);
66807004
6681− if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)),
7005+ if (copy_to_user((void __user *)((unsigned long)
7006+ get_unaligned((unsigned long *)sense_ptr)),
66827007 sense, ioc->sense_len)) {
66837008 dev_err(&instance->pdev->dev, "Failed to copy out to user "
66847009 "sense data\n");
@@ -7047,6 +7372,13 @@ megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t coun · 362 unmodified lines
70477372 static DRIVER_ATTR(dbg_lvl, S_IRUGO|S_IWUSR, megasas_sysfs_show_dbg_lvl,
70487373 megasas_sysfs_set_dbg_lvl);
70497374
7375+static inline void megasas_remove_scsi_device(struct scsi_device *sdev)
7376+{
7377+ sdev_printk(KERN_INFO, sdev, "SCSI device is removed\n");
7378+ scsi_remove_device(sdev);
7379+ scsi_device_put(sdev);
7380+}
7381+
70507382 static void
70517383 megasas_aen_polling(struct work_struct *work)
70527384 {
@@ -7151,10 +7483,8 @@ megasas_aen_polling(struct work_struct *work) · 98 unmodified lines
71517483 else
71527484 scsi_device_put(sdev1);
71537485 } else {
7154− if (sdev1) {
7155− scsi_remove_device(sdev1);
7156− scsi_device_put(sdev1);
7157− }
7486+ if (sdev1)
7487+ megasas_remove_scsi_device(sdev1);
71587488 }
71597489 }
71607490 }
@@ -7171,10 +7501,8 @@ megasas_aen_polling(struct work_struct *work) · 10 unmodified lines
71717501 else
71727502 scsi_device_put(sdev1);
71737503 } else {
7174− if (sdev1) {
7175− scsi_remove_device(sdev1);
7176− scsi_device_put(sdev1);
7177− }
7504+ if (sdev1)
7505+ megasas_remove_scsi_device(sdev1);
71787506 }
71797507 }
71807508 }
drivers/scsi/megaraid/megaraid_sas_fp.c+231−237
@@ -77,7 +77,6 @@ MODULE_PARM_DESC(lb_pending_cmds, "Change raid-1 load balancing outstanding " · 76 unmodified lines
7777 #endif
7878 #define TRUE 1
7979
80−#define SPAN_DEBUG 0
8180 #define SPAN_ROW_SIZE(map, ld, index_) (MR_LdSpanPtrGet(ld, index_, map)->spanRowSize)
8281 #define SPAN_ROW_DATA_SIZE(map_, ld, index_) (MR_LdSpanPtrGet(ld, index_, map)->spanRowDataSize)
8382 #define SPAN_INVALID 0xff
@@ -155,12 +154,17 @@ __le16 MR_PdDevHandleGet(u32 pd, struct MR_DRV_RAID_MAP_ALL *map) · 71 unmodified lines
155154 return map->raidMap.devHndlInfo[pd].curDevHdl;
156155 }
157156
157+static u8 MR_PdInterfaceTypeGet(u32 pd, struct MR_DRV_RAID_MAP_ALL *map)
158+{
159+ return map->raidMap.devHndlInfo[pd].interfaceType;
160+}
161+
158162 u16 MR_GetLDTgtId(u32 ld, struct MR_DRV_RAID_MAP_ALL *map)
159163 {
160164 return le16_to_cpu(map->raidMap.ldSpanMap[ld].ldRaid.targetId);
161165 }
162166
163−u8 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map)
167+u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_DRV_RAID_MAP_ALL *map)
164168 {
165169 return map->raidMap.ldTgtIdToLd[ldTgtId];
166170 }
@@ -179,18 +183,108 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance) · 12 unmodified lines
179183 struct fusion_context *fusion = instance->ctrl_context;
180184 struct MR_FW_RAID_MAP_ALL *fw_map_old = NULL;
181185 struct MR_FW_RAID_MAP *pFwRaidMap = NULL;
182− int i;
186+ int i, j;
183187 u16 ld_count;
188+ struct MR_FW_RAID_MAP_DYNAMIC *fw_map_dyn;
189+ struct MR_FW_RAID_MAP_EXT *fw_map_ext;
190+ struct MR_RAID_MAP_DESC_TABLE *desc_table;
184191
185192
186193 struct MR_DRV_RAID_MAP_ALL *drv_map =
187194 fusion->ld_drv_map[(instance->map_id & 1)];
188195 struct MR_DRV_RAID_MAP *pDrvRaidMap = &drv_map->raidMap;
196+ void *raid_map_data = NULL;
197+
198+ memset(drv_map, 0, fusion->drv_map_sz);
199+ memset(pDrvRaidMap->ldTgtIdToLd,
200+ 0xff, (sizeof(u16) * MAX_LOGICAL_DRIVES_DYN));
201+
202+ if (instance->max_raid_mapsize) {
203+ fw_map_dyn = fusion->ld_map[(instance->map_id & 1)];
204+ desc_table =
205+ (struct MR_RAID_MAP_DESC_TABLE *)((void *)fw_map_dyn + le32_to_cpu(fw_map_dyn->desc_table_offset));
206+ if (desc_table != fw_map_dyn->raid_map_desc_table)
207+ dev_dbg(&instance->pdev->dev, "offsets of desc table are not matching desc %p original %p\n",
208+ desc_table, fw_map_dyn->raid_map_desc_table);
209+
210+ ld_count = (u16)le16_to_cpu(fw_map_dyn->ld_count);
211+ pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
212+ pDrvRaidMap->fpPdIoTimeoutSec =
213+ fw_map_dyn->fp_pd_io_timeout_sec;
214+ pDrvRaidMap->totalSize =
215+ cpu_to_le32(sizeof(struct MR_DRV_RAID_MAP_ALL));
216+ /* point to actual data starting point*/
217+ raid_map_data = (void *)fw_map_dyn +
218+ le32_to_cpu(fw_map_dyn->desc_table_offset) +
219+ le32_to_cpu(fw_map_dyn->desc_table_size);
220+
221+ for (i = 0; i < le32_to_cpu(fw_map_dyn->desc_table_num_elements); ++i) {
222+ switch (le32_to_cpu(desc_table->raid_map_desc_type)) {
223+ case RAID_MAP_DESC_TYPE_DEVHDL_INFO:
224+ fw_map_dyn->dev_hndl_info =
225+ (struct MR_DEV_HANDLE_INFO *)(raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
226+ memcpy(pDrvRaidMap->devHndlInfo,
227+ fw_map_dyn->dev_hndl_info,
228+ sizeof(struct MR_DEV_HANDLE_INFO) *
229+ le32_to_cpu(desc_table->raid_map_desc_elements));
230+ break;
231+ case RAID_MAP_DESC_TYPE_TGTID_INFO:
232+ fw_map_dyn->ld_tgt_id_to_ld =
233+ (u16 *)(raid_map_data +
234+ le32_to_cpu(desc_table->raid_map_desc_offset));
235+ for (j = 0; j < le32_to_cpu(desc_table->raid_map_desc_elements); j++) {
236+ pDrvRaidMap->ldTgtIdToLd[j] =
237+ le16_to_cpu(fw_map_dyn->ld_tgt_id_to_ld[j]);
238+ }
239+ break;
240+ case RAID_MAP_DESC_TYPE_ARRAY_INFO:
241+ fw_map_dyn->ar_map_info =
242+ (struct MR_ARRAY_INFO *)
243+ (raid_map_data + le32_to_cpu(desc_table->raid_map_desc_offset));
244+ memcpy(pDrvRaidMap->arMapInfo,
245+ fw_map_dyn->ar_map_info,
246+ sizeof(struct MR_ARRAY_INFO) *
247+ le32_to_cpu(desc_table->raid_map_desc_elements));
248+ break;
249+ case RAID_MAP_DESC_TYPE_SPAN_INFO:
250+ fw_map_dyn->ld_span_map =
251+ (struct MR_LD_SPAN_MAP *)
252+ (raid_map_data +
253+ le32_to_cpu(desc_table->raid_map_desc_offset));
254+ memcpy(pDrvRaidMap->ldSpanMap,
255+ fw_map_dyn->ld_span_map,
256+ sizeof(struct MR_LD_SPAN_MAP) *
257+ le32_to_cpu(desc_table->raid_map_desc_elements));
258+ break;
259+ default:
260+ dev_dbg(&instance->pdev->dev, "wrong number of desctableElements %d\n",
261+ fw_map_dyn->desc_table_num_elements);
262+ }
263+ ++desc_table;
264+ }
265+
266+ } else if (instance->supportmax256vd) {
267+ fw_map_ext =
268+ (struct MR_FW_RAID_MAP_EXT *)fusion->ld_map[(instance->map_id & 1)];
269+ ld_count = (u16)le16_to_cpu(fw_map_ext->ldCount);
270+ if (ld_count > MAX_LOGICAL_DRIVES_EXT) {
271+ dev_dbg(&instance->pdev->dev, "megaraid_sas: LD count exposed in RAID map in not valid\n");
272+ return;
273+ }
274+
275+ pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
276+ pDrvRaidMap->fpPdIoTimeoutSec = fw_map_ext->fpPdIoTimeoutSec;
277+ for (i = 0; i < (MAX_LOGICAL_DRIVES_EXT); i++)
278+ pDrvRaidMap->ldTgtIdToLd[i] =
279+ (u16)fw_map_ext->ldTgtIdToLd[i];
280+ memcpy(pDrvRaidMap->ldSpanMap, fw_map_ext->ldSpanMap,
281+ sizeof(struct MR_LD_SPAN_MAP) * ld_count);
282+ memcpy(pDrvRaidMap->arMapInfo, fw_map_ext->arMapInfo,
283+ sizeof(struct MR_ARRAY_INFO) * MAX_API_ARRAYS_EXT);
284+ memcpy(pDrvRaidMap->devHndlInfo, fw_map_ext->devHndlInfo,
285+ sizeof(struct MR_DEV_HANDLE_INFO) *
286+ MAX_RAIDMAP_PHYSICAL_DEVICES);
189287
190− if (instance->supportmax256vd) {
191− memcpy(fusion->ld_drv_map[instance->map_id & 1],
192− fusion->ld_map[instance->map_id & 1],
193− fusion->current_map_sz);
194288 /* New Raid map will not set totalSize, so keep expected value
195289 * for legacy code in ValidateMapInfo
196290 */
@@ -201,50 +295,14 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance) · 4 unmodified lines
201295 fusion->ld_map[(instance->map_id & 1)];
202296 pFwRaidMap = &fw_map_old->raidMap;
203297 ld_count = (u16)le32_to_cpu(pFwRaidMap->ldCount);
204−
205−#if VD_EXT_DEBUG
206− for (i = 0; i < ld_count; i++) {
207− dev_dbg(&instance->pdev->dev, "(%d) :Index 0x%x "
208− "Target Id 0x%x Seq Num 0x%x Size 0/%llx\n",
209− instance->unique_id, i,
210− fw_map_old->raidMap.ldSpanMap[i].ldRaid.targetId,
211− fw_map_old->raidMap.ldSpanMap[i].ldRaid.seqNum,
212− fw_map_old->raidMap.ldSpanMap[i].ldRaid.size);
213− }
214−#endif
215−
216− memset(drv_map, 0, fusion->drv_map_sz);
217298 pDrvRaidMap->totalSize = pFwRaidMap->totalSize;
218299 pDrvRaidMap->ldCount = (__le16)cpu_to_le16(ld_count);
219300 pDrvRaidMap->fpPdIoTimeoutSec = pFwRaidMap->fpPdIoTimeoutSec;
220301 for (i = 0; i < MAX_RAIDMAP_LOGICAL_DRIVES + MAX_RAIDMAP_VIEWS; i++)
221302 pDrvRaidMap->ldTgtIdToLd[i] =
222303 (u8)pFwRaidMap->ldTgtIdToLd[i];
223− for (i = (MAX_RAIDMAP_LOGICAL_DRIVES + MAX_RAIDMAP_VIEWS);
224− i < MAX_LOGICAL_DRIVES_EXT; i++)
225− pDrvRaidMap->ldTgtIdToLd[i] = 0xff;
226304 for (i = 0; i < ld_count; i++) {
227305 pDrvRaidMap->ldSpanMap[i] = pFwRaidMap->ldSpanMap[i];
228−#if VD_EXT_DEBUG
229− dev_dbg(&instance->pdev->dev,
230− "pFwRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x "
231− "pFwRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x "
232− "size 0x%x\n", i, i,
233− pFwRaidMap->ldSpanMap[i].ldRaid.targetId,
234− pFwRaidMap->ldSpanMap[i].ldRaid.seqNum,
235− (u32)pFwRaidMap->ldSpanMap[i].ldRaid.rowSize);
236− dev_dbg(&instance->pdev->dev,
237− "pDrvRaidMap->ldSpanMap[%d].ldRaid.targetId 0x%x "
238− "pDrvRaidMap->ldSpanMap[%d].ldRaid.seqNum 0x%x "
239− "size 0x%x\n", i, i,
240− pDrvRaidMap->ldSpanMap[i].ldRaid.targetId,
241− pDrvRaidMap->ldSpanMap[i].ldRaid.seqNum,
242− (u32)pDrvRaidMap->ldSpanMap[i].ldRaid.rowSize);
243− dev_dbg(&instance->pdev->dev, "Driver raid map all %p "
244− "raid map %p LD RAID MAP %p/%p\n", drv_map,
245− pDrvRaidMap, &pFwRaidMap->ldSpanMap[i].ldRaid,
246− &pDrvRaidMap->ldSpanMap[i].ldRaid);
247−#endif
248306 }
249307 memcpy(pDrvRaidMap->arMapInfo, pFwRaidMap->arMapInfo,
250308 sizeof(struct MR_ARRAY_INFO) * MAX_RAIDMAP_ARRAYS);
@@ -265,7 +323,7 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance) · 14 unmodified lines
265323 struct LD_LOAD_BALANCE_INFO *lbInfo;
266324 PLD_SPAN_INFO ldSpanInfo;
267325 struct MR_LD_RAID *raid;
268− u16 ldCount, num_lds;
326+ u16 num_lds, i;
269327 u16 ld;
270328 u32 expected_size;
271329
@@ -279,7 +337,9 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance) · 7 unmodified lines
279337 lbInfo = fusion->load_balance_info;
280338 ldSpanInfo = fusion->log_to_span;
281339
282− if (instance->supportmax256vd)
340+ if (instance->max_raid_mapsize)
341+ expected_size = sizeof(struct MR_DRV_RAID_MAP_ALL);
342+ else if (instance->supportmax256vd)
283343 expected_size = sizeof(struct MR_FW_RAID_MAP_EXT);
284344 else
285345 expected_size =
@@ -287,8 +347,10 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance) · 1 unmodified line
287347 (sizeof(struct MR_LD_SPAN_MAP) * le16_to_cpu(pDrvRaidMap->ldCount)));
288348
289349 if (le32_to_cpu(pDrvRaidMap->totalSize) != expected_size) {
290− dev_err(&instance->pdev->dev, "map info structure size 0x%x is not matching with ld count\n",
291− (unsigned int) expected_size);
350+ dev_dbg(&instance->pdev->dev, "megasas: map info structure size 0x%x",
351+ le32_to_cpu(pDrvRaidMap->totalSize));
352+ dev_dbg(&instance->pdev->dev, "is not matching expected size 0x%x\n",
353+ (unsigned int)expected_size);
292354 dev_err(&instance->pdev->dev, "megasas: span map %x, pDrvRaidMap->totalSize : %x\n",
293355 (unsigned int)sizeof(struct MR_LD_SPAN_MAP),
294356 le32_to_cpu(pDrvRaidMap->totalSize));
@@ -298,15 +360,23 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance) · 3 unmodified lines
298360 if (instance->UnevenSpanSupport)
299361 mr_update_span_set(drv_map, ldSpanInfo);
300362
301− mr_update_load_balance_params(drv_map, lbInfo);
363+ if (lbInfo)
364+ mr_update_load_balance_params(drv_map, lbInfo);
302365
303366 num_lds = le16_to_cpu(drv_map->raidMap.ldCount);
304367
305368 /*Convert Raid capability values to CPU arch */
306− for (ldCount = 0; ldCount < num_lds; ldCount++) {
307− ld = MR_TargetIdToLdGet(ldCount, drv_map);
369+ for (i = 0; (num_lds > 0) && (i < MAX_LOGICAL_DRIVES_EXT); i++) {
370+ ld = MR_TargetIdToLdGet(i, drv_map);
371+
372+ /* For non existing VDs, iterate to next VD*/
373+ if (ld >= (MAX_LOGICAL_DRIVES_EXT - 1))
374+ continue;
375+
308376 raid = MR_LdRaidGet(ld, drv_map);
309377 le32_to_cpus((u32 *)&raid->capability);
378+
379+ num_lds--;
310380 }
311381
312382 return 1;
@@ -345,91 +415,6 @@ u32 MR_GetSpanBlock(u32 ld, u64 row, u64 *span_blk, · 32 unmodified lines
345415 return SPAN_INVALID;
346416 }
347417
348−/*
349−******************************************************************************
350−*
351−* Function to print info about span set created in driver from FW raid map
352−*
353−* Inputs :
354−* map - LD map
355−* ldSpanInfo - ldSpanInfo per HBA instance
356−*/
357−#if SPAN_DEBUG
358−static int getSpanInfo(struct MR_DRV_RAID_MAP_ALL *map,
359− PLD_SPAN_INFO ldSpanInfo)
360−{
361−
362− u8 span;
363− u32 element;
364− struct MR_LD_RAID *raid;
365− LD_SPAN_SET *span_set;
366− struct MR_QUAD_ELEMENT *quad;
367− int ldCount;
368− u16 ld;
369−
370− for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES_EXT; ldCount++) {
371− ld = MR_TargetIdToLdGet(ldCount, map);
372− if (ld >= (MAX_LOGICAL_DRIVES_EXT - 1))
373− continue;
374− raid = MR_LdRaidGet(ld, map);
375− dev_dbg(&instance->pdev->dev, "LD %x: span_depth=%x\n",
376− ld, raid->spanDepth);
377− for (span = 0; span < raid->spanDepth; span++)
378− dev_dbg(&instance->pdev->dev, "Span=%x,"
379− " number of quads=%x\n", span,
380− le32_to_cpu(map->raidMap.ldSpanMap[ld].spanBlock[span].
381− block_span_info.noElements));
382− for (element = 0; element < MAX_QUAD_DEPTH; element++) {
383− span_set = &(ldSpanInfo[ld].span_set[element]);
384− if (span_set->span_row_data_width == 0)
385− break;
386−
387− dev_dbg(&instance->pdev->dev, "Span Set %x:"
388− "width=%x, diff=%x\n", element,
389− (unsigned int)span_set->span_row_data_width,
390− (unsigned int)span_set->diff);
391− dev_dbg(&instance->pdev->dev, "logical LBA"
392− "start=0x%08lx, end=0x%08lx\n",
393− (long unsigned int)span_set->log_start_lba,
394− (long unsigned int)span_set->log_end_lba);
395− dev_dbg(&instance->pdev->dev, "span row start=0x%08lx,"
396− " end=0x%08lx\n",
397− (long unsigned int)span_set->span_row_start,
398− (long unsigned int)span_set->span_row_end);
399− dev_dbg(&instance->pdev->dev, "data row start=0x%08lx,"
400− " end=0x%08lx\n",
401− (long unsigned int)span_set->data_row_start,
402− (long unsigned int)span_set->data_row_end);
403− dev_dbg(&instance->pdev->dev, "data strip start=0x%08lx,"
404− " end=0x%08lx\n",
405− (long unsigned int)span_set->data_strip_start,
406− (long unsigned int)span_set->data_strip_end);
407−
408− for (span = 0; span < raid->spanDepth; span++) {
409− if (le32_to_cpu(map->raidMap.ldSpanMap[ld].spanBlock[span].
410− block_span_info.noElements) >=
411− element + 1) {
412− quad = &map->raidMap.ldSpanMap[ld].
413− spanBlock[span].block_span_info.
414− quad[element];
415− dev_dbg(&instance->pdev->dev, "Span=%x,"
416− "Quad=%x, diff=%x\n", span,
417− element, le32_to_cpu(quad->diff));
418− dev_dbg(&instance->pdev->dev,
419− "offset_in_span=0x%08lx\n",
420− (long unsigned int)le64_to_cpu(quad->offsetInSpan));
421− dev_dbg(&instance->pdev->dev,
422− "logical start=0x%08lx, end=0x%08lx\n",
423− (long unsigned int)le64_to_cpu(quad->logStart),
424− (long unsigned int)le64_to_cpu(quad->logEnd));
425− }
426− }
427− }
428− }
429− return 0;
430−}
431−#endif
432−
433418 /*
434419 ******************************************************************************
435420 *
@@ -543,19 +528,7 @@ static u64 get_row_from_strip(struct megasas_instance *instance, · 107 unmodified lines
543528 else
544529 break;
545530 }
546−#if SPAN_DEBUG
547− dev_info(&instance->pdev->dev, "Strip 0x%llx,"
548− "span_set_Strip 0x%llx, span_set_Row 0x%llx"
549− "data width 0x%llx span offset 0x%x\n", strip,
550− (unsigned long long)span_set_Strip,
551− (unsigned long long)span_set_Row,
552− (unsigned long long)span_set->span_row_data_width,
553− span_offset);
554− dev_info(&instance->pdev->dev, "For strip 0x%llx"
555− "row is 0x%llx\n", strip,
556− (unsigned long long) span_set->data_row_start +
557− (unsigned long long) span_set_Row + (span_offset - 1));
558−#endif
531+
559532 retval = (span_set->data_row_start + span_set_Row +
560533 (span_offset - 1));
561534 return retval;
@@ -672,11 +645,7 @@ static u32 get_arm_from_strip(struct megasas_instance *instance, · 110 unmodified lines
672645 else
673646 break;
674647 }
675−#if SPAN_DEBUG
676− dev_info(&instance->pdev->dev, "get_arm_from_strip:"
677− "for ld=0x%x strip=0x%lx arm is 0x%x\n", ld,
678− (long unsigned int)strip, (strip_offset - span_offset));
679−#endif
648+
680649 retval = (strip_offset - span_offset);
681650 return retval;
682651 }
@@ -737,16 +706,18 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld, · 54 unmodified lines
737706 struct MR_DRV_RAID_MAP_ALL *map)
738707 {
739708 struct MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
740− u32 pd, arRef;
709+ u32 pd, arRef, r1_alt_pd;
741710 u8 physArm, span;
742711 u64 row;
743712 u8 retval = TRUE;
744713 u64 *pdBlock = &io_info->pdBlock;
745714 __le16 *pDevHandle = &io_info->devHandle;
715+ u8 *pPdInterface = &io_info->pd_interface;
746716 u32 logArm, rowMod, armQ, arm;
747717 struct fusion_context *fusion;
748718
749719 fusion = instance->ctrl_context;
720+ *pDevHandle = cpu_to_le16(MR_DEVHANDLE_INVALID);
750721
751722 /*Get row and span from io_info for Uneven Span IO.*/
752723 row = io_info->start_row;
@@ -772,27 +743,46 @@ static u8 mr_spanset_get_phy_params(struct megasas_instance *instance, u32 ld, · 19 unmodified lines
772743 arRef = MR_LdSpanArrayGet(ld, span, map);
773744 pd = MR_ArPdGet(arRef, physArm, map);
774745
775− if (pd != MR_PD_INVALID)
746+ if (pd != MR_PD_INVALID) {
776747 *pDevHandle = MR_PdDevHandleGet(pd, map);
777− else {
778− *pDevHandle = cpu_to_le16(MR_PD_INVALID);
748+ *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
749+ /* get second pd also for raid 1/10 fast path writes*/
750+ if (instance->is_ventura &&
751+ (raid->level == 1) &&
752+ !io_info->isRead) {
753+ r1_alt_pd = MR_ArPdGet(arRef, physArm + 1, map);
754+ if (r1_alt_pd != MR_PD_INVALID)
755+ io_info->r1_alt_dev_handle =
756+ MR_PdDevHandleGet(r1_alt_pd, map);
757+ }
758+ } else {
779759 if ((raid->level >= 5) &&
780760 ((fusion->adapter_type == THUNDERBOLT_SERIES) ||
781761 ((fusion->adapter_type == INVADER_SERIES) &&
782762 (raid->regTypeReqOnRead != REGION_TYPE_UNUSED))))
783− pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
763+ pRAID_Context->reg_lock_flags = REGION_TYPE_EXCLUSIVE;
784764 else if (raid->level == 1) {
785765 physArm = physArm + 1;
786766 pd = MR_ArPdGet(arRef, physArm, map);
787− if (pd != MR_PD_INVALID)
767+ if (pd != MR_PD_INVALID) {
788768 *pDevHandle = MR_PdDevHandleGet(pd, map);
769+ *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
770+ }
789771 }
790772 }
791773
792774 *pdBlock += stripRef + le64_to_cpu(MR_LdSpanPtrGet(ld, span, map)->startBlk);
793− pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) |
794− physArm;
795− io_info->span_arm = pRAID_Context->spanArm;
775+ if (instance->is_ventura) {
776+ ((struct RAID_CONTEXT_G35 *)pRAID_Context)->span_arm =
777+ (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
778+ io_info->span_arm =
779+ (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
780+ } else {
781+ pRAID_Context->span_arm =
782+ (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
783+ io_info->span_arm = pRAID_Context->span_arm;
784+ }
785+ io_info->pd_after_lb = pd;
796786 return retval;
797787 }
798788
@@ -819,16 +809,17 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow, · 20 unmodified lines
819809 struct MR_DRV_RAID_MAP_ALL *map)
820810 {
821811 struct MR_LD_RAID *raid = MR_LdRaidGet(ld, map);
822− u32 pd, arRef;
812+ u32 pd, arRef, r1_alt_pd;
823813 u8 physArm, span;
824814 u64 row;
825815 u8 retval = TRUE;
826816 u64 *pdBlock = &io_info->pdBlock;
827817 __le16 *pDevHandle = &io_info->devHandle;
818+ u8 *pPdInterface = &io_info->pd_interface;
828819 struct fusion_context *fusion;
829820
830821 fusion = instance->ctrl_context;
831−
822+ *pDevHandle = cpu_to_le16(MR_DEVHANDLE_INVALID);
832823
833824 row = mega_div64_32(stripRow, raid->rowDataSize);
834825
@@ -867,31 +858,49 @@ u8 MR_GetPhyParams(struct megasas_instance *instance, u32 ld, u64 stripRow, · 32 unmodified lines
867858 arRef = MR_LdSpanArrayGet(ld, span, map);
868859 pd = MR_ArPdGet(arRef, physArm, map); /* Get the pd */
869860
870− if (pd != MR_PD_INVALID)
861+ if (pd != MR_PD_INVALID) {
871862 /* Get dev handle from Pd. */
872863 *pDevHandle = MR_PdDevHandleGet(pd, map);
873− else {
874− /* set dev handle as invalid. */
875− *pDevHandle = cpu_to_le16(MR_PD_INVALID);
864+ *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
865+ /* get second pd also for raid 1/10 fast path writes*/
866+ if (instance->is_ventura &&
867+ (raid->level == 1) &&
868+ !io_info->isRead) {
869+ r1_alt_pd = MR_ArPdGet(arRef, physArm + 1, map);
870+ if (r1_alt_pd != MR_PD_INVALID)
871+ io_info->r1_alt_dev_handle =
872+ MR_PdDevHandleGet(r1_alt_pd, map);
873+ }
874+ } else {
876875 if ((raid->level >= 5) &&
877876 ((fusion->adapter_type == THUNDERBOLT_SERIES) ||
878877 ((fusion->adapter_type == INVADER_SERIES) &&
879878 (raid->regTypeReqOnRead != REGION_TYPE_UNUSED))))
880− pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
879+ pRAID_Context->reg_lock_flags = REGION_TYPE_EXCLUSIVE;
881880 else if (raid->level == 1) {
882881 /* Get alternate Pd. */
883882 physArm = physArm + 1;
884883 pd = MR_ArPdGet(arRef, physArm, map);
885− if (pd != MR_PD_INVALID)
884+ if (pd != MR_PD_INVALID) {
886885 /* Get dev handle from Pd */
887886 *pDevHandle = MR_PdDevHandleGet(pd, map);
887+ *pPdInterface = MR_PdInterfaceTypeGet(pd, map);
888+ }
888889 }
889890 }
890891
891892 *pdBlock += stripRef + le64_to_cpu(MR_LdSpanPtrGet(ld, span, map)->startBlk);
892− pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) |
893− physArm;
894− io_info->span_arm = pRAID_Context->spanArm;
893+ if (instance->is_ventura) {
894+ ((struct RAID_CONTEXT_G35 *)pRAID_Context)->span_arm =
895+ (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
896+ io_info->span_arm =
897+ (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
898+ } else {
899+ pRAID_Context->span_arm =
900+ (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
901+ io_info->span_arm = pRAID_Context->span_arm;
902+ }
903+ io_info->pd_after_lb = pd;
895904 return retval;
896905 }
897906
@@ -912,7 +921,7 @@ MR_BuildRaidContext(struct megasas_instance *instance, · 14 unmodified lines
912921 {
913922 struct fusion_context *fusion;
914923 struct MR_LD_RAID *raid;
915− u32 ld, stripSize, stripe_mask;
924+ u32 stripSize, stripe_mask;
916925 u64 endLba, endStrip, endRow, start_row, start_strip;
917926 u64 regStart;
918927 u32 regSize;
@@ -924,6 +933,7 @@ MR_BuildRaidContext(struct megasas_instance *instance, · 5 unmodified lines
924933 u8 retval = 0;
925934 u8 startlba_span = SPAN_INVALID;
926935 u64 *pdBlock = &io_info->pdBlock;
936+ u16 ld;
927937
928938 ldStartBlock = io_info->ldStartBlock;
929939 numBlocks = io_info->numBlocks;
@@ -935,6 +945,8 @@ MR_BuildRaidContext(struct megasas_instance *instance, · 5 unmodified lines
935945
936946 ld = MR_TargetIdToLdGet(ldTgtId, map);
937947 raid = MR_LdRaidGet(ld, map);
948+ /*check read ahead bit*/
949+ io_info->ra_capable = raid->capability.ra_capable;
938950
939951 /*
940952 * if rowDataSize @RAID map and spanRowDataSize @SPAN INFO are zero
@@ -996,17 +1008,6 @@ MR_BuildRaidContext(struct megasas_instance *instance, · 55 unmodified lines
9961008 }
9971009 io_info->start_span = startlba_span;
9981010 io_info->start_row = start_row;
999−#if SPAN_DEBUG
1000− dev_dbg(&instance->pdev->dev, "Check Span number from %s %d"
1001− "for row 0x%llx, start strip 0x%llx end strip 0x%llx"
1002− " span 0x%x\n", __func__, __LINE__,
1003− (unsigned long long)start_row,
1004− (unsigned long long)start_strip,
1005− (unsigned long long)endStrip, startlba_span);
1006− dev_dbg(&instance->pdev->dev, "start_row 0x%llx endRow 0x%llx"
1007− "Start span 0x%x\n", (unsigned long long)start_row,
1008− (unsigned long long)endRow, startlba_span);
1009−#endif
10101011 } else {
10111012 start_row = mega_div64_32(start_strip, raid->rowDataSize);
10121013 endRow = mega_div64_32(endStrip, raid->rowDataSize);
@@ -1093,20 +1094,20 @@ MR_BuildRaidContext(struct megasas_instance *instance, · 80 unmodified lines
10931094 regSize += stripSize;
10941095 }
10951096
1096− pRAID_Context->timeoutValue =
1097+ pRAID_Context->timeout_value =
10971098 cpu_to_le16(raid->fpIoTimeoutForLd ?
10981099 raid->fpIoTimeoutForLd :
10991100 map->raidMap.fpPdIoTimeoutSec);
11001101 if (fusion->adapter_type == INVADER_SERIES)
1101− pRAID_Context->regLockFlags = (isRead) ?
1102+ pRAID_Context->reg_lock_flags = (isRead) ?
11021103 raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
1103− else
1104− pRAID_Context->regLockFlags = (isRead) ?
1104+ else if (!instance->is_ventura)
1105+ pRAID_Context->reg_lock_flags = (isRead) ?
11051106 REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
1106− pRAID_Context->VirtualDiskTgtId = raid->targetId;
1107− pRAID_Context->regLockRowLBA = cpu_to_le64(regStart);
1108− pRAID_Context->regLockLength = cpu_to_le32(regSize);
1109− pRAID_Context->configSeqNum = raid->seqNum;
1107+ pRAID_Context->virtual_disk_tgt_id = raid->targetId;
1108+ pRAID_Context->reg_lock_row_lba = cpu_to_le64(regStart);
1109+ pRAID_Context->reg_lock_length = cpu_to_le32(regSize);
1110+ pRAID_Context->config_seq_num = raid->seqNum;
11101111 /* save pointer to raid->LUN array */
11111112 *raidLUN = raid->LUN;
11121113
@@ -1122,7 +1123,7 @@ MR_BuildRaidContext(struct megasas_instance *instance, · 9 unmodified lines
11221123 ref_in_start_stripe, io_info,
11231124 pRAID_Context, map);
11241125 /* If IO on an invalid Pd, then FP is not possible.*/
1125− if (io_info->devHandle == cpu_to_le16(MR_PD_INVALID))
1126+ if (io_info->devHandle == MR_DEVHANDLE_INVALID)
11261127 io_info->fpOkForIo = FALSE;
11271128 return retval;
11281129 } else if (isRead) {
@@ -1140,12 +1141,6 @@ MR_BuildRaidContext(struct megasas_instance *instance, · 11 unmodified lines
11401141 return TRUE;
11411142 }
11421143 }
1143−
1144−#if SPAN_DEBUG
1145− /* Just for testing what arm we get for strip.*/
1146− if (io_info->IoforUnevenSpan)
1147− get_arm_from_strip(instance, ld, start_strip, map);
1148−#endif
11491144 return TRUE;
11501145 }
11511146
@@ -1259,10 +1254,6 @@ void mr_update_span_set(struct MR_DRV_RAID_MAP_ALL *map, · 107 unmodified lines
12591254 break;
12601255 }
12611256 }
1262−#if SPAN_DEBUG
1263− getSpanInfo(map, ldSpanInfo);
1264−#endif
1265−
12661257 }
12671258
12681259 void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *drv_map,
@@ -1293,11 +1284,12 @@ void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *drv_map, · 24 unmodified lines
12931284 }
12941285
12951286 u8 megasas_get_best_arm_pd(struct megasas_instance *instance,
1296− struct LD_LOAD_BALANCE_INFO *lbInfo, struct IO_REQUEST_INFO *io_info)
1287+ struct LD_LOAD_BALANCE_INFO *lbInfo,
1288+ struct IO_REQUEST_INFO *io_info,
1289+ struct MR_DRV_RAID_MAP_ALL *drv_map)
12971290 {
1298− struct fusion_context *fusion;
12991291 struct MR_LD_RAID *raid;
1300− struct MR_DRV_RAID_MAP_ALL *drv_map;
1292+ u16 pd1_dev_handle;
13011293 u16 pend0, pend1, ld;
13021294 u64 diff0, diff1;
13031295 u8 bestArm, pd0, pd1, span, arm;
@@ -1310,9 +1302,6 @@ u8 megasas_get_best_arm_pd(struct megasas_instance *instance, · 6 unmodified lines
13101302 >> RAID_CTX_SPANARM_SPAN_SHIFT);
13111303 arm = (io_info->span_arm & RAID_CTX_SPANARM_ARM_MASK);
13121304
1313−
1314− fusion = instance->ctrl_context;
1315− drv_map = fusion->ld_drv_map[(instance->map_id & 1)];
13161305 ld = MR_TargetIdToLdGet(io_info->ldTgtId, drv_map);
13171306 raid = MR_LdRaidGet(ld, drv_map);
13181307 span_row_size = instance->UnevenSpanSupport ?
@@ -1323,47 +1312,52 @@ u8 megasas_get_best_arm_pd(struct megasas_instance *instance, · 4 unmodified lines
13231312 pd1 = MR_ArPdGet(arRef, (arm + 1) >= span_row_size ?
13241313 (arm + 1 - span_row_size) : arm + 1, drv_map);
13251314
1326− /* get the pending cmds for the data and mirror arms */
1327− pend0 = atomic_read(&lbInfo->scsi_pending_cmds[pd0]);
1328− pend1 = atomic_read(&lbInfo->scsi_pending_cmds[pd1]);
1315+ /* Get PD1 Dev Handle */
1316+
1317+ pd1_dev_handle = MR_PdDevHandleGet(pd1, drv_map);
13291318
1330− /* Determine the disk whose head is nearer to the req. block */
1331− diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[pd0]);
1332− diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[pd1]);
1333− bestArm = (diff0 <= diff1 ? arm : arm ^ 1);
1319+ if (pd1_dev_handle == MR_DEVHANDLE_INVALID) {
1320+ bestArm = arm;
1321+ } else {
1322+ /* get the pending cmds for the data and mirror arms */
1323+ pend0 = atomic_read(&lbInfo->scsi_pending_cmds[pd0]);
1324+ pend1 = atomic_read(&lbInfo->scsi_pending_cmds[pd1]);
13341325
1335− if ((bestArm == arm && pend0 > pend1 + lb_pending_cmds) ||
1336− (bestArm != arm && pend1 > pend0 + lb_pending_cmds))
1337− bestArm ^= 1;
1326+ /* Determine the disk whose head is nearer to the req. block */
1327+ diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[pd0]);
1328+ diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[pd1]);
1329+ bestArm = (diff0 <= diff1 ? arm : arm ^ 1);
1330+
1331+ /* Make balance count from 16 to 4 to
1332+ * keep driver in sync with Firmware
1333+ */
1334+ if ((bestArm == arm && pend0 > pend1 + lb_pending_cmds) ||
1335+ (bestArm != arm && pend1 > pend0 + lb_pending_cmds))
1336+ bestArm ^= 1;
1337+
1338+ /* Update the last accessed block on the correct pd */
1339+ io_info->span_arm =
1340+ (span << RAID_CTX_SPANARM_SPAN_SHIFT) | bestArm;
1341+ io_info->pd_after_lb = (bestArm == arm) ? pd0 : pd1;
1342+ }
13381343
1339− /* Update the last accessed block on the correct pd */
1340− io_info->pd_after_lb = (bestArm == arm) ? pd0 : pd1;
13411344 lbInfo->last_accessed_block[io_info->pd_after_lb] = block + count - 1;
1342− io_info->span_arm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | bestArm;
1343−#if SPAN_DEBUG
1344− if (arm != bestArm)
1345− dev_dbg(&instance->pdev->dev, "LSI Debug R1 Load balance "
1346− "occur - span 0x%x arm 0x%x bestArm 0x%x "
1347− "io_info->span_arm 0x%x\n",
1348− span, arm, bestArm, io_info->span_arm);
1349−#endif
13501345 return io_info->pd_after_lb;
13511346 }
13521347
13531348 __le16 get_updated_dev_handle(struct megasas_instance *instance,
1354− struct LD_LOAD_BALANCE_INFO *lbInfo, struct IO_REQUEST_INFO *io_info)
1349+ struct LD_LOAD_BALANCE_INFO *lbInfo,
1350+ struct IO_REQUEST_INFO *io_info,
1351+ struct MR_DRV_RAID_MAP_ALL *drv_map)
13551352 {
13561353 u8 arm_pd;
13571354 __le16 devHandle;
1358− struct fusion_context *fusion;
1359− struct MR_DRV_RAID_MAP_ALL *drv_map;
1360−
1361− fusion = instance->ctrl_context;
1362− drv_map = fusion->ld_drv_map[(instance->map_id & 1)];
13631355
13641356 /* get best new arm (PD ID) */
1365− arm_pd = megasas_get_best_arm_pd(instance, lbInfo, io_info);
1357+ arm_pd = megasas_get_best_arm_pd(instance, lbInfo, io_info, drv_map);
13661358 devHandle = MR_PdDevHandleGet(arm_pd, drv_map);
1359+ io_info->pd_interface = MR_PdInterfaceTypeGet(arm_pd, drv_map);
13671360 atomic_inc(&lbInfo->scsi_pending_cmds[arm_pd]);
1361+
13681362 return devHandle;
13691363 }
drivers/scsi/megaraid/megaraid_sas_fusion.c+1080−254
@@ -47,6 +47,7 @@ · 46 unmodified lines
4747 #include <linux/blkdev.h>
4848 #include <linux/mutex.h>
4949 #include <linux/poll.h>
50+#include <linux/vmalloc.h>
5051
5152 #include <scsi/scsi.h>
5253 #include <scsi/scsi_cmnd.h>
@@ -181,32 +182,44 @@ inline void megasas_return_cmd_fusion(struct megasas_instance *instance, · 128 unmodified lines
181182 struct megasas_cmd_fusion *cmd)
182183 {
183184 cmd->scmd = NULL;
184− memset(cmd->io_request, 0, sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
185+ memset(cmd->io_request, 0, MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
186+ cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
187+ cmd->cmd_completed = false;
185188 }
186189
187190 /**
188191 * megasas_fire_cmd_fusion - Sends command to the FW
192+ * @instance: Adapter soft state
193+ * @req_desc: 32bit or 64bit Request descriptor
194+ *
195+ * Perform PCI Write. Ventura supports 32 bit Descriptor.
196+ * Prior to Ventura (12G) MR controller supports 64 bit Descriptor.
189197 */
198+
190199 static void
191200 megasas_fire_cmd_fusion(struct megasas_instance *instance,
192201 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc)
193202 {
203+ if (instance->is_ventura)
204+ writel(le32_to_cpu(req_desc->u.low),
205+ &instance->reg_set->inbound_single_queue_port);
206+ else {
194207 #if defined(writeq) && defined(CONFIG_64BIT)
195− u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) |
196− le32_to_cpu(req_desc->u.low));
208+ u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) |
209+ le32_to_cpu(req_desc->u.low));
197210
198− writeq(req_data, &instance->reg_set->inbound_low_queue_port);
211+ writeq(req_data, &instance->reg_set->inbound_low_queue_port);
199212 #else
200− unsigned long flags;
201−
202− spin_lock_irqsave(&instance->hba_lock, flags);
203− writel(le32_to_cpu(req_desc->u.low),
204− &instance->reg_set->inbound_low_queue_port);
205− writel(le32_to_cpu(req_desc->u.high),
206− &instance->reg_set->inbound_high_queue_port);
207− mmiowb();
208− spin_unlock_irqrestore(&instance->hba_lock, flags);
213+ unsigned long flags;
214+ spin_lock_irqsave(&instance->hba_lock, flags);
215+ writel(le32_to_cpu(req_desc->u.low),
216+ &instance->reg_set->inbound_low_queue_port);
217+ writel(le32_to_cpu(req_desc->u.high),
218+ &instance->reg_set->inbound_high_queue_port);
219+ mmiowb();
220+ spin_unlock_irqrestore(&instance->hba_lock, flags);
209221 #endif
222+ }
210223 }
211224
212225 /**
@@ -229,7 +242,10 @@ megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_c · 16 unmodified lines
229242
230243 reg_set = instance->reg_set;
231244
232− cur_max_fw_cmds = readl(&instance->reg_set->outbound_scratch_pad_3) & 0x00FFFF;
245+ /* ventura FW does not fill outbound_scratch_pad_3 with queue depth */
246+ if (!instance->is_ventura)
247+ cur_max_fw_cmds =
248+ readl(&instance->reg_set->outbound_scratch_pad_3) & 0x00FFFF;
233249
234250 if (dual_qdepth_disable || !cur_max_fw_cmds)
235251 cur_max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF;
@@ -243,7 +259,7 @@ megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_c · 7 unmodified lines
243259
244260 if (fw_boot_context == OCR_CONTEXT) {
245261 cur_max_fw_cmds = cur_max_fw_cmds - 1;
246− if (cur_max_fw_cmds <= instance->max_fw_cmds) {
262+ if (cur_max_fw_cmds < instance->max_fw_cmds) {
247263 instance->cur_can_queue =
248264 cur_max_fw_cmds - (MEGASAS_FUSION_INTERNAL_CMDS +
249265 MEGASAS_FUSION_IOCTL_CMDS);
@@ -255,7 +271,8 @@ megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_c · 5 unmodified lines
255271 instance->ldio_threshold = ldio_threshold;
256272
257273 if (!instance->is_rdpq)
258− instance->max_fw_cmds = min_t(u16, instance->max_fw_cmds, 1024);
274+ instance->max_fw_cmds =
275+ min_t(u16, instance->max_fw_cmds, 1024);
259276
260277 if (reset_devices)
261278 instance->max_fw_cmds = min(instance->max_fw_cmds,
@@ -271,7 +288,14 @@ megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_c · 9 unmodified lines
271288 (MEGASAS_FUSION_INTERNAL_CMDS +
272289 MEGASAS_FUSION_IOCTL_CMDS);
273290 instance->cur_can_queue = instance->max_scsi_cmds;
291+ instance->host->can_queue = instance->cur_can_queue;
274292 }
293+
294+ if (instance->is_ventura)
295+ instance->max_mpt_cmds =
296+ instance->max_fw_cmds * RAID_1_PEER_CMDS;
297+ else
298+ instance->max_mpt_cmds = instance->max_fw_cmds;
275299 }
276300 /**
277301 * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool
@@ -285,7 +309,7 @@ megasas_free_cmds_fusion(struct megasas_instance *instance) · 7 unmodified lines
285309 struct megasas_cmd_fusion *cmd;
286310
287311 /* SG, Sense */
288− for (i = 0; i < instance->max_fw_cmds; i++) {
312+ for (i = 0; i < instance->max_mpt_cmds; i++) {
289313 cmd = fusion->cmd_list[i];
290314 if (cmd) {
291315 if (cmd->sg_frame)
@@ -329,7 +353,7 @@ megasas_free_cmds_fusion(struct megasas_instance *instance) · 37 unmodified lines
329353
330354
331355 /* cmd_list */
332− for (i = 0; i < instance->max_fw_cmds; i++)
356+ for (i = 0; i < instance->max_mpt_cmds; i++)
333357 kfree(fusion->cmd_list[i]);
334358
335359 kfree(fusion->cmd_list);
@@ -343,7 +367,7 @@ megasas_free_cmds_fusion(struct megasas_instance *instance) · 7 unmodified lines
343367 static int megasas_create_sg_sense_fusion(struct megasas_instance *instance)
344368 {
345369 int i;
346− u32 max_cmd;
370+ u16 max_cmd;
347371 struct fusion_context *fusion;
348372 struct megasas_cmd_fusion *cmd;
349373
@@ -353,7 +377,8 @@ static int megasas_create_sg_sense_fusion(struct megasas_instance *instance) · 3 unmodified lines
353377
354378 fusion->sg_dma_pool =
355379 pci_pool_create("mr_sg", instance->pdev,
356− instance->max_chain_frame_sz, 4, 0);
380+ instance->max_chain_frame_sz,
381+ MR_DEFAULT_NVME_PAGE_SIZE, 0);
357382 /* SCSI_SENSE_BUFFERSIZE = 96 bytes */
358383 fusion->sense_dma_pool =
359384 pci_pool_create("mr_sense", instance->pdev,
@@ -381,33 +406,47 @@ static int megasas_create_sg_sense_fusion(struct megasas_instance *instance) · 21 unmodified lines
381406 return -ENOMEM;
382407 }
383408 }
409+
410+ /* create sense buffer for the raid 1/10 fp */
411+ for (i = max_cmd; i < instance->max_mpt_cmds; i++) {
412+ cmd = fusion->cmd_list[i];
413+ cmd->sense = pci_pool_alloc(fusion->sense_dma_pool,
414+ GFP_KERNEL, &cmd->sense_phys_addr);
415+ if (!cmd->sense) {
416+ dev_err(&instance->pdev->dev,
417+ "Failed from %s %d\n", __func__, __LINE__);
418+ return -ENOMEM;
419+ }
420+ }
421+
384422 return 0;
385423 }
386424
387425 int
388426 megasas_alloc_cmdlist_fusion(struct megasas_instance *instance)
389427 {
390− u32 max_cmd, i;
428+ u32 max_mpt_cmd, i;
391429 struct fusion_context *fusion;
392430
393431 fusion = instance->ctrl_context;
394432
395− max_cmd = instance->max_fw_cmds;
433+ max_mpt_cmd = instance->max_mpt_cmds;
396434
397435 /*
398436 * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers.
399437 * Allocate the dynamic array first and then allocate individual
400438 * commands.
401439 */
402− fusion->cmd_list = kzalloc(sizeof(struct megasas_cmd_fusion *) * max_cmd,
403− GFP_KERNEL);
440+ fusion->cmd_list =
441+ kzalloc(sizeof(struct megasas_cmd_fusion *) * max_mpt_cmd,
442+ GFP_KERNEL);
404443 if (!fusion->cmd_list) {
405444 dev_err(&instance->pdev->dev,
406445 "Failed from %s %d\n", __func__, __LINE__);
407446 return -ENOMEM;
408447 }
409448
410− for (i = 0; i < max_cmd; i++) {
449+ for (i = 0; i < max_mpt_cmd; i++) {
411450 fusion->cmd_list[i] = kzalloc(sizeof(struct megasas_cmd_fusion),
412451 GFP_KERNEL);
413452 if (!fusion->cmd_list[i]) {
@@ -539,7 +578,7 @@ megasas_alloc_rdpq_fusion(struct megasas_instance *instance) · 125 unmodified lines
539578 }
540579
541580 fusion->rdpq_virt[i].RDPQBaseAddress =
542− fusion->reply_frames_desc_phys[i];
581+ cpu_to_le64(fusion->reply_frames_desc_phys[i]);
543582
544583 reply_desc = fusion->reply_frames_desc[i];
545584 for (j = 0; j < fusion->reply_q_depth; j++, reply_desc++)
@@ -642,13 +681,14 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 96 unmodified lines
642681 */
643682
644683 /* SMID 0 is reserved. Set SMID/index from 1 */
645− for (i = 0; i < instance->max_fw_cmds; i++) {
684+ for (i = 0; i < instance->max_mpt_cmds; i++) {
646685 cmd = fusion->cmd_list[i];
647686 offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i;
648687 memset(cmd, 0, sizeof(struct megasas_cmd_fusion));
649688 cmd->index = i + 1;
650689 cmd->scmd = NULL;
651− cmd->sync_cmd_idx = (i >= instance->max_scsi_cmds) ?
690+ cmd->sync_cmd_idx =
691+ (i >= instance->max_scsi_cmds && i < instance->max_fw_cmds) ?
652692 (i - instance->max_scsi_cmds) :
653693 (u32)ULONG_MAX; /* Set to Invalid */
654694 cmd->instance = instance;
@@ -658,6 +698,7 @@ megasas_alloc_cmds_fusion(struct megasas_instance *instance) · 3 unmodified lines
658698 memset(cmd->io_request, 0,
659699 sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
660700 cmd->io_request_phys_addr = io_req_base_phys + offset;
701+ cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
661702 }
662703
663704 if (megasas_create_sg_sense_fusion(instance))
@@ -725,6 +766,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance) · 61 unmodified lines
725766 const char *sys_info;
726767 MFI_CAPABILITIES *drv_ops;
727768 u32 scratch_pad_2;
769+ unsigned long flags;
728770
729771 fusion = instance->ctrl_context;
730772
@@ -781,6 +823,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance) · 50 unmodified lines
781823 MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE : 0;
782824 IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys);
783825 IOCInitMessage->HostMSIxVectors = instance->msix_vectors;
826+ IOCInitMessage->HostPageSize = MR_DEFAULT_NVME_PAGE_SHIFT;
784827 init_frame = (struct megasas_init_frame *)cmd->frame;
785828 memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
786829
@@ -796,7 +839,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance) · 9 unmodified lines
796839 drv_ops = (MFI_CAPABILITIES *) &(init_frame->driver_operations);
797840
798841 /* driver support Extended MSIX */
799− if (fusion->adapter_type == INVADER_SERIES)
842+ if (fusion->adapter_type >= INVADER_SERIES)
800843 drv_ops->mfi_capabilities.support_additional_msix = 1;
801844 /* driver supports HA / Remote LUN over Fast Path interface */
802845 drv_ops->mfi_capabilities.support_fp_remote_lun = 1;
@@ -813,6 +856,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance) · 10 unmodified lines
813856 drv_ops->mfi_capabilities.support_ext_queue_depth = 1;
814857
815858 drv_ops->mfi_capabilities.support_qd_throttling = 1;
859+ drv_ops->mfi_capabilities.support_pd_map_target_id = 1;
816860 /* Convert capability to LE32 */
817861 cpu_to_le32s((u32 *)&init_frame->driver_operations.mfi_capabilities);
818862
@@ -850,7 +894,14 @@ megasas_ioc_init_fusion(struct megasas_instance *instance) · 31 unmodified lines
850894 break;
851895 }
852896
853− megasas_fire_cmd_fusion(instance, &req_desc);
897+ /* For Ventura also IOC INIT required 64 bit Descriptor write. */
898+ spin_lock_irqsave(&instance->hba_lock, flags);
899+ writel(le32_to_cpu(req_desc.u.low),
900+ &instance->reg_set->inbound_low_queue_port);
901+ writel(le32_to_cpu(req_desc.u.high),
902+ &instance->reg_set->inbound_high_queue_port);
903+ mmiowb();
904+ spin_unlock_irqrestore(&instance->hba_lock, flags);
854905
855906 wait_and_poll(instance, cmd, MFI_POLL_TIMEOUT_SECS);
856907
@@ -1009,11 +1060,6 @@ megasas_get_ld_map_info(struct megasas_instance *instance) · 152 unmodified lines
10091060
10101061 memset(ci, 0, fusion->max_map_sz);
10111062 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1012−#if VD_EXT_DEBUG
1013− dev_dbg(&instance->pdev->dev,
1014− "%s sending MR_DCMD_LD_MAP_GET_INFO with size %d\n",
1015− __func__, cpu_to_le32(size_map_info));
1016−#endif
10171063 dcmd->cmd = MFI_CMD_DCMD;
10181064 dcmd->cmd_status = 0xFF;
10191065 dcmd->sge_count = 1;
@@ -1065,10 +1111,11 @@ megasas_get_map_info(struct megasas_instance *instance) · 45 unmodified lines
10651111 int
10661112 megasas_sync_map_info(struct megasas_instance *instance)
10671113 {
1068− int ret = 0, i;
1114+ int i;
10691115 struct megasas_cmd *cmd;
10701116 struct megasas_dcmd_frame *dcmd;
1071− u32 size_sync_info, num_lds;
1117+ u16 num_lds;
1118+ u32 size_sync_info;
10721119 struct fusion_context *fusion;
10731120 struct MR_LD_TARGET_SYNC *ci = NULL;
10741121 struct MR_DRV_RAID_MAP_ALL *map;
@@ -1134,7 +1181,7 @@ megasas_sync_map_info(struct megasas_instance *instance) · 59 unmodified lines
11341181
11351182 instance->instancet->issue_dcmd(instance, cmd);
11361183
1137− return ret;
1184+ return 0;
11381185 }
11391186
11401187 /*
@@ -1220,7 +1267,8 @@ megasas_init_adapter_fusion(struct megasas_instance *instance) · 79 unmodified lines
12201267 {
12211268 struct megasas_register_set __iomem *reg_set;
12221269 struct fusion_context *fusion;
1223− u32 max_cmd, scratch_pad_2;
1270+ u16 max_cmd;
1271+ u32 scratch_pad_2;
12241272 int i = 0, count;
12251273
12261274 fusion = instance->ctrl_context;
@@ -1229,13 +1277,6 @@ megasas_init_adapter_fusion(struct megasas_instance *instance) · 2 unmodified lines
12291277
12301278 megasas_fusion_update_can_queue(instance, PROBE_CONTEXT);
12311279
1232− /*
1233− * Reduce the max supported cmds by 1. This is to ensure that the
1234− * reply_q_sz (1 more than the max cmd that driver may send)
1235− * does not exceed max cmds that the FW can support
1236− */
1237− instance->max_fw_cmds = instance->max_fw_cmds-1;
1238−
12391280 /*
12401281 * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames
12411282 */
@@ -1247,12 +1288,12 @@ megasas_init_adapter_fusion(struct megasas_instance *instance) · 5 unmodified lines
12471288 fusion->reply_q_depth = 2 * (((max_cmd + 1 + 15)/16)*16);
12481289
12491290 fusion->request_alloc_sz =
1250− sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *max_cmd;
1291+ sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * instance->max_mpt_cmds;
12511292 fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)
12521293 *(fusion->reply_q_depth);
12531294 fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE +
1254− (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE *
1255− (max_cmd + 1)); /* Extra 1 for SMID 0 */
1295+ (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1296+ * (instance->max_mpt_cmds + 1)); /* Extra 1 for SMID 0 */
12561297
12571298 scratch_pad_2 = readl(&instance->reg_set->outbound_scratch_pad_2);
12581299 /* If scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK is set,
@@ -1302,7 +1343,7 @@ megasas_init_adapter_fusion(struct megasas_instance *instance) · 43 unmodified lines
13021343 fusion->last_reply_idx[i] = 0;
13031344
13041345 /*
1305− * For fusion adapters, 3 commands for IOCTL and 5 commands
1346+ * For fusion adapters, 3 commands for IOCTL and 8 commands
13061347 * for driver's internal DCMDs.
13071348 */
13081349 instance->max_scsi_cmds = instance->max_fw_cmds -
@@ -1331,6 +1372,7 @@ megasas_init_adapter_fusion(struct megasas_instance *instance) · 22 unmodified lines
13311372 }
13321373
13331374 instance->flag_ieee = 1;
1375+ instance->r1_ldio_hint_default = MR_R1_LDIO_PIGGYBACK_DEFAULT;
13341376 fusion->fast_path_io = 0;
13351377
13361378 fusion->drv_map_pages = get_order(fusion->drv_map_sz);
@@ -1388,96 +1430,348 @@ fail_alloc_mfi_cmds: · 51 unmodified lines
13881430 */
13891431
13901432 void
1391−map_cmd_status(struct megasas_cmd_fusion *cmd, u8 status, u8 ext_status)
1433+map_cmd_status(struct fusion_context *fusion,
1434+ struct scsi_cmnd *scmd, u8 status, u8 ext_status,
1435+ u32 data_length, u8 *sense)
13921436 {
1437+ u8 cmd_type;
1438+ int resid;
13931439
1440+ cmd_type = megasas_cmd_type(scmd);
13941441 switch (status) {
13951442
13961443 case MFI_STAT_OK:
1397− cmd->scmd->result = DID_OK << 16;
1444+ scmd->result = DID_OK << 16;
13981445 break;
13991446
14001447 case MFI_STAT_SCSI_IO_FAILED:
14011448 case MFI_STAT_LD_INIT_IN_PROGRESS:
1402− cmd->scmd->result = (DID_ERROR << 16) | ext_status;
1449+ scmd->result = (DID_ERROR << 16) | ext_status;
14031450 break;
14041451
14051452 case MFI_STAT_SCSI_DONE_WITH_ERROR:
14061453
1407− cmd->scmd->result = (DID_OK << 16) | ext_status;
1454+ scmd->result = (DID_OK << 16) | ext_status;
14081455 if (ext_status == SAM_STAT_CHECK_CONDITION) {
1409− memset(cmd->scmd->sense_buffer, 0,
1456+ memset(scmd->sense_buffer, 0,
14101457 SCSI_SENSE_BUFFERSIZE);
1411− memcpy(cmd->scmd->sense_buffer, cmd->sense,
1458+ memcpy(scmd->sense_buffer, sense,
14121459 SCSI_SENSE_BUFFERSIZE);
1413− cmd->scmd->result |= DRIVER_SENSE << 24;
1460+ scmd->result |= DRIVER_SENSE << 24;
14141461 }
1462+
1463+ /*
1464+ * If the IO request is partially completed, then MR FW will
1465+ * update "io_request->DataLength" field with actual number of
1466+ * bytes transferred.Driver will set residual bytes count in
1467+ * SCSI command structure.
1468+ */
1469+ resid = (scsi_bufflen(scmd) - data_length);
1470+ scsi_set_resid(scmd, resid);
1471+
1472+ if (resid &&
1473+ ((cmd_type == READ_WRITE_LDIO) ||
1474+ (cmd_type == READ_WRITE_SYSPDIO)))
1475+ scmd_printk(KERN_INFO, scmd, "BRCM Debug mfi stat 0x%x, data len"
1476+ " requested/completed 0x%x/0x%x\n",
1477+ status, scsi_bufflen(scmd), data_length);
14151478 break;
14161479
14171480 case MFI_STAT_LD_OFFLINE:
14181481 case MFI_STAT_DEVICE_NOT_FOUND:
1419− cmd->scmd->result = DID_BAD_TARGET << 16;
1482+ scmd->result = DID_BAD_TARGET << 16;
14201483 break;
14211484 case MFI_STAT_CONFIG_SEQ_MISMATCH:
1422− cmd->scmd->result = DID_IMM_RETRY << 16;
1485+ scmd->result = DID_IMM_RETRY << 16;
14231486 break;
14241487 default:
1425− dev_printk(KERN_DEBUG, &cmd->instance->pdev->dev, "FW status %#x\n", status);
1426− cmd->scmd->result = DID_ERROR << 16;
1488+ scmd->result = DID_ERROR << 16;
14271489 break;
14281490 }
14291491 }
14301492
1493+/**
1494+ * megasas_is_prp_possible -
1495+ * Checks if native NVMe PRPs can be built for the IO
1496+ *
1497+ * @instance: Adapter soft state
1498+ * @scmd: SCSI command from the mid-layer
1499+ * @sge_count: scatter gather element count.
1500+ *
1501+ * Returns: true: PRPs can be built
1502+ * false: IEEE SGLs needs to be built
1503+ */
1504+static bool
1505+megasas_is_prp_possible(struct megasas_instance *instance,
1506+ struct scsi_cmnd *scmd, int sge_count)
1507+{
1508+ struct fusion_context *fusion;
1509+ int i;
1510+ u32 data_length = 0;
1511+ struct scatterlist *sg_scmd;
1512+ bool build_prp = false;
1513+ u32 mr_nvme_pg_size;
1514+
1515+ mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
1516+ MR_DEFAULT_NVME_PAGE_SIZE);
1517+ fusion = instance->ctrl_context;
1518+ data_length = scsi_bufflen(scmd);
1519+ sg_scmd = scsi_sglist(scmd);
1520+
1521+ /*
1522+ * NVMe uses one PRP for each page (or part of a page)
1523+ * look at the data length - if 4 pages or less then IEEE is OK
1524+ * if > 5 pages then we need to build a native SGL
1525+ * if > 4 and <= 5 pages, then check physical address of 1st SG entry
1526+ * if this first size in the page is >= the residual beyond 4 pages
1527+ * then use IEEE, otherwise use native SGL
1528+ */
1529+
1530+ if (data_length > (mr_nvme_pg_size * 5)) {
1531+ build_prp = true;
1532+ } else if ((data_length > (mr_nvme_pg_size * 4)) &&
1533+ (data_length <= (mr_nvme_pg_size * 5))) {
1534+ /* check if 1st SG entry size is < residual beyond 4 pages */
1535+ if (sg_dma_len(sg_scmd) < (data_length - (mr_nvme_pg_size * 4)))
1536+ build_prp = true;
1537+ }
1538+
1539+/*
1540+ * Below code detects gaps/holes in IO data buffers.
1541+ * What does holes/gaps mean?
1542+ * Any SGE except first one in a SGL starts at non NVME page size
1543+ * aligned address OR Any SGE except last one in a SGL ends at
1544+ * non NVME page size boundary.
1545+ *
1546+ * Driver has already informed block layer by setting boundary rules for
1547+ * bio merging done at NVME page size boundary calling kernel API
1548+ * blk_queue_virt_boundary inside slave_config.
1549+ * Still there is possibility of IO coming with holes to driver because of
1550+ * IO merging done by IO scheduler.
1551+ *
1552+ * With SCSI BLK MQ enabled, there will be no IO with holes as there is no
1553+ * IO scheduling so no IO merging.
1554+ *
1555+ * With SCSI BLK MQ disabled, IO scheduler may attempt to merge IOs and
1556+ * then sending IOs with holes.
1557+ *
1558+ * Though driver can request block layer to disable IO merging by calling-
1559+ * queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue) but
1560+ * user may tune sysfs parameter- nomerges again to 0 or 1.
1561+ *
1562+ * If in future IO scheduling is enabled with SCSI BLK MQ,
1563+ * this algorithm to detect holes will be required in driver
1564+ * for SCSI BLK MQ enabled case as well.
1565+ *
1566+ *
1567+ */
1568+ scsi_for_each_sg(scmd, sg_scmd, sge_count, i) {
1569+ if ((i != 0) && (i != (sge_count - 1))) {
1570+ if (mega_mod64(sg_dma_len(sg_scmd), mr_nvme_pg_size) ||
1571+ mega_mod64(sg_dma_address(sg_scmd),
1572+ mr_nvme_pg_size)) {
1573+ build_prp = false;
1574+ atomic_inc(&instance->sge_holes_type1);
1575+ break;
1576+ }
1577+ }
1578+
1579+ if ((sge_count > 1) && (i == 0)) {
1580+ if ((mega_mod64((sg_dma_address(sg_scmd) +
1581+ sg_dma_len(sg_scmd)),
1582+ mr_nvme_pg_size))) {
1583+ build_prp = false;
1584+ atomic_inc(&instance->sge_holes_type2);
1585+ break;
1586+ }
1587+ }
1588+
1589+ if ((sge_count > 1) && (i == (sge_count - 1))) {
1590+ if (mega_mod64(sg_dma_address(sg_scmd),
1591+ mr_nvme_pg_size)) {
1592+ build_prp = false;
1593+ atomic_inc(&instance->sge_holes_type3);
1594+ break;
1595+ }
1596+ }
1597+ }
1598+
1599+ return build_prp;
1600+}
1601+
1602+/**
1603+ * megasas_make_prp_nvme -
1604+ * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only
1605+ *
1606+ * @instance: Adapter soft state
1607+ * @scmd: SCSI command from the mid-layer
1608+ * @sgl_ptr: SGL to be filled in
1609+ * @cmd: Fusion command frame
1610+ * @sge_count: scatter gather element count.
1611+ *
1612+ * Returns: true: PRPs are built
1613+ * false: IEEE SGLs needs to be built
1614+ */
1615+static bool
1616+megasas_make_prp_nvme(struct megasas_instance *instance, struct scsi_cmnd *scmd,
1617+ struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
1618+ struct megasas_cmd_fusion *cmd, int sge_count)
1619+{
1620+ int sge_len, offset, num_prp_in_chain = 0;
1621+ struct MPI25_IEEE_SGE_CHAIN64 *main_chain_element, *ptr_first_sgl;
1622+ u64 *ptr_sgl;
1623+ dma_addr_t ptr_sgl_phys;
1624+ u64 sge_addr;
1625+ u32 page_mask, page_mask_result;
1626+ struct scatterlist *sg_scmd;
1627+ u32 first_prp_len;
1628+ bool build_prp = false;
1629+ int data_len = scsi_bufflen(scmd);
1630+ struct fusion_context *fusion;
1631+ u32 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
1632+ MR_DEFAULT_NVME_PAGE_SIZE);
1633+
1634+ fusion = instance->ctrl_context;
1635+
1636+ build_prp = megasas_is_prp_possible(instance, scmd, sge_count);
1637+
1638+ if (!build_prp)
1639+ return false;
1640+
1641+ /*
1642+ * Nvme has a very convoluted prp format. One prp is required
1643+ * for each page or partial page. Driver need to split up OS sg_list
1644+ * entries if it is longer than one page or cross a page
1645+ * boundary. Driver also have to insert a PRP list pointer entry as
1646+ * the last entry in each physical page of the PRP list.
1647+ *
1648+ * NOTE: The first PRP "entry" is actually placed in the first
1649+ * SGL entry in the main message as IEEE 64 format. The 2nd
1650+ * entry in the main message is the chain element, and the rest
1651+ * of the PRP entries are built in the contiguous pcie buffer.
1652+ */
1653+ page_mask = mr_nvme_pg_size - 1;
1654+ ptr_sgl = (u64 *)cmd->sg_frame;
1655+ ptr_sgl_phys = cmd->sg_frame_phys_addr;
1656+ memset(ptr_sgl, 0, instance->max_chain_frame_sz);
1657+
1658+ /* Build chain frame element which holds all prps except first*/
1659+ main_chain_element = (struct MPI25_IEEE_SGE_CHAIN64 *)
1660+ ((u8 *)sgl_ptr + sizeof(struct MPI25_IEEE_SGE_CHAIN64));
1661+
1662+ main_chain_element->Address = cpu_to_le64(ptr_sgl_phys);
1663+ main_chain_element->NextChainOffset = 0;
1664+ main_chain_element->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
1665+ IEEE_SGE_FLAGS_SYSTEM_ADDR |
1666+ MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP;
1667+
1668+ /* Build first prp, sge need not to be page aligned*/
1669+ ptr_first_sgl = sgl_ptr;
1670+ sg_scmd = scsi_sglist(scmd);
1671+ sge_addr = sg_dma_address(sg_scmd);
1672+ sge_len = sg_dma_len(sg_scmd);
1673+
1674+ offset = (u32)(sge_addr & page_mask);
1675+ first_prp_len = mr_nvme_pg_size - offset;
1676+
1677+ ptr_first_sgl->Address = cpu_to_le64(sge_addr);
1678+ ptr_first_sgl->Length = cpu_to_le32(first_prp_len);
1679+
1680+ data_len -= first_prp_len;
1681+
1682+ if (sge_len > first_prp_len) {
1683+ sge_addr += first_prp_len;
1684+ sge_len -= first_prp_len;
1685+ } else if (sge_len == first_prp_len) {
1686+ sg_scmd = sg_next(sg_scmd);
1687+ sge_addr = sg_dma_address(sg_scmd);
1688+ sge_len = sg_dma_len(sg_scmd);
1689+ }
1690+
1691+ for (;;) {
1692+ offset = (u32)(sge_addr & page_mask);
1693+
1694+ /* Put PRP pointer due to page boundary*/
1695+ page_mask_result = (uintptr_t)(ptr_sgl + 1) & page_mask;
1696+ if (unlikely(!page_mask_result)) {
1697+ scmd_printk(KERN_NOTICE,
1698+ scmd, "page boundary ptr_sgl: 0x%p\n",
1699+ ptr_sgl);
1700+ ptr_sgl_phys += 8;
1701+ *ptr_sgl = cpu_to_le64(ptr_sgl_phys);
1702+ ptr_sgl++;
1703+ num_prp_in_chain++;
1704+ }
1705+
1706+ *ptr_sgl = cpu_to_le64(sge_addr);
1707+ ptr_sgl++;
1708+ ptr_sgl_phys += 8;
1709+ num_prp_in_chain++;
1710+
1711+ sge_addr += mr_nvme_pg_size;
1712+ sge_len -= mr_nvme_pg_size;
1713+ data_len -= mr_nvme_pg_size;
1714+
1715+ if (data_len <= 0)
1716+ break;
1717+
1718+ if (sge_len > 0)
1719+ continue;
1720+
1721+ sg_scmd = sg_next(sg_scmd);
1722+ sge_addr = sg_dma_address(sg_scmd);
1723+ sge_len = sg_dma_len(sg_scmd);
1724+ }
1725+
1726+ main_chain_element->Length =
1727+ cpu_to_le32(num_prp_in_chain * sizeof(u64));
1728+
1729+ atomic_inc(&instance->prp_sgl);
1730+ return build_prp;
1731+}
1732+
14311733 /**
14321734 * megasas_make_sgl_fusion - Prepares 32-bit SGL
14331735 * @instance: Adapter soft state
14341736 * @scp: SCSI command from the mid-layer
14351737 * @sgl_ptr: SGL to be filled in
14361738 * @cmd: cmd we are working on
1739+ * @sge_count sge count
14371740 *
1438− * If successful, this function returns the number of SG elements.
14391741 */
1440−static int
1742+static void
14411743 megasas_make_sgl_fusion(struct megasas_instance *instance,
14421744 struct scsi_cmnd *scp,
14431745 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
1444− struct megasas_cmd_fusion *cmd)
1746+ struct megasas_cmd_fusion *cmd, int sge_count)
14451747 {
1446− int i, sg_processed, sge_count;
1748+ int i, sg_processed;
14471749 struct scatterlist *os_sgl;
14481750 struct fusion_context *fusion;
14491751
14501752 fusion = instance->ctrl_context;
14511753
1452− if (fusion->adapter_type == INVADER_SERIES) {
1754+ if (fusion->adapter_type >= INVADER_SERIES) {
14531755 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr;
14541756 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
14551757 sgl_ptr_end->Flags = 0;
14561758 }
14571759
1458− sge_count = scsi_dma_map(scp);
1459−
1460− BUG_ON(sge_count < 0);
1461−
1462− if (sge_count > instance->max_num_sge || !sge_count)
1463− return sge_count;
1464−
14651760 scsi_for_each_sg(scp, os_sgl, sge_count, i) {
14661761 sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl));
14671762 sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl));
14681763 sgl_ptr->Flags = 0;
1469− if (fusion->adapter_type == INVADER_SERIES)
1764+ if (fusion->adapter_type >= INVADER_SERIES)
14701765 if (i == sge_count - 1)
14711766 sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
14721767 sgl_ptr++;
1473−
14741768 sg_processed = i + 1;
14751769
14761770 if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) &&
14771771 (sge_count > fusion->max_sge_in_main_msg)) {
14781772
14791773 struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
1480− if (fusion->adapter_type == INVADER_SERIES) {
1774+ if (fusion->adapter_type >= INVADER_SERIES) {
14811775 if ((le16_to_cpu(cmd->io_request->IoFlags) &
14821776 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) !=
14831777 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH)
@@ -1493,7 +1787,7 @@ megasas_make_sgl_fusion(struct megasas_instance *instance, · 9 unmodified lines
14931787 sg_chain = sgl_ptr;
14941788 /* Prepare chain element */
14951789 sg_chain->NextChainOffset = 0;
1496− if (fusion->adapter_type == INVADER_SERIES)
1790+ if (fusion->adapter_type >= INVADER_SERIES)
14971791 sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT;
14981792 else
14991793 sg_chain->Flags =
@@ -1507,6 +1801,45 @@ megasas_make_sgl_fusion(struct megasas_instance *instance, · 7 unmodified lines
15071801 memset(sgl_ptr, 0, instance->max_chain_frame_sz);
15081802 }
15091803 }
1804+ atomic_inc(&instance->ieee_sgl);
1805+}
1806+
1807+/**
1808+ * megasas_make_sgl - Build Scatter Gather List(SGLs)
1809+ * @scp: SCSI command pointer
1810+ * @instance: Soft instance of controller
1811+ * @cmd: Fusion command pointer
1812+ *
1813+ * This function will build sgls based on device type.
1814+ * For nvme drives, there is different way of building sgls in nvme native
1815+ * format- PRPs(Physical Region Page).
1816+ *
1817+ * Returns the number of sg lists actually used, zero if the sg lists
1818+ * is NULL, or -ENOMEM if the mapping failed
1819+ */
1820+static
1821+int megasas_make_sgl(struct megasas_instance *instance, struct scsi_cmnd *scp,
1822+ struct megasas_cmd_fusion *cmd)
1823+{
1824+ int sge_count;
1825+ bool build_prp = false;
1826+ struct MPI25_IEEE_SGE_CHAIN64 *sgl_chain64;
1827+
1828+ sge_count = scsi_dma_map(scp);
1829+
1830+ if ((sge_count > instance->max_num_sge) || (sge_count <= 0))
1831+ return sge_count;
1832+
1833+ sgl_chain64 = (struct MPI25_IEEE_SGE_CHAIN64 *)&cmd->io_request->SGL;
1834+ if ((le16_to_cpu(cmd->io_request->IoFlags) &
1835+ MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) &&
1836+ (cmd->pd_interface == NVME_PD))
1837+ build_prp = megasas_make_prp_nvme(instance, scp, sgl_chain64,
1838+ cmd, sge_count);
1839+
1840+ if (!build_prp)
1841+ megasas_make_sgl_fusion(instance, scp, sgl_chain64,
1842+ cmd, sge_count);
15101843
15111844 return sge_count;
15121845 }
@@ -1525,7 +1858,7 @@ megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len, · 12 unmodified lines
15251858 struct MR_DRV_RAID_MAP_ALL *local_map_ptr, u32 ref_tag)
15261859 {
15271860 struct MR_LD_RAID *raid;
1528− u32 ld;
1861+ u16 ld;
15291862 u64 start_blk = io_info->pdBlock;
15301863 u8 *cdb = io_request->CDB.CDB32;
15311864 u32 num_blocks = io_info->numBlocks;
@@ -1574,6 +1907,7 @@ megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len, · 42 unmodified lines
15741907 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
15751908 MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP |
15761909 MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG |
1910+ MPI25_SCSIIO_EEDPFLAGS_DO_NOT_DISABLE_MODE |
15771911 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD);
15781912 } else {
15791913 io_request->EEDPFlags = cpu_to_le16(
@@ -1687,6 +2021,166 @@ megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len, · 107 unmodified lines
16872021 }
16882022 }
16892023
2024+/**
2025+ * megasas_stream_detect - stream detection on read and and write IOs
2026+ * @instance: Adapter soft state
2027+ * @cmd: Command to be prepared
2028+ * @io_info: IO Request info
2029+ *
2030+ */
2031+
2032+/** stream detection on read and and write IOs */
2033+static void megasas_stream_detect(struct megasas_instance *instance,
2034+ struct megasas_cmd_fusion *cmd,
2035+ struct IO_REQUEST_INFO *io_info)
2036+{
2037+ struct fusion_context *fusion = instance->ctrl_context;
2038+ u32 device_id = io_info->ldTgtId;
2039+ struct LD_STREAM_DETECT *current_ld_sd
2040+ = fusion->stream_detect_by_ld[device_id];
2041+ u32 *track_stream = &current_ld_sd->mru_bit_map, stream_num;
2042+ u32 shifted_values, unshifted_values;
2043+ u32 index_value_mask, shifted_values_mask;
2044+ int i;
2045+ bool is_read_ahead = false;
2046+ struct STREAM_DETECT *current_sd;
2047+ /* find possible stream */
2048+ for (i = 0; i < MAX_STREAMS_TRACKED; ++i) {
2049+ stream_num = (*track_stream >>
2050+ (i * BITS_PER_INDEX_STREAM)) &
2051+ STREAM_MASK;
2052+ current_sd = &current_ld_sd->stream_track[stream_num];
2053+ /* if we found a stream, update the raid
2054+ * context and also update the mruBitMap
2055+ */
2056+ /* boundary condition */
2057+ if ((current_sd->next_seq_lba) &&
2058+ (io_info->ldStartBlock >= current_sd->next_seq_lba) &&
2059+ (io_info->ldStartBlock <= (current_sd->next_seq_lba + 32)) &&
2060+ (current_sd->is_read == io_info->isRead)) {
2061+
2062+ if ((io_info->ldStartBlock != current_sd->next_seq_lba) &&
2063+ ((!io_info->isRead) || (!is_read_ahead)))
2064+ /*
2065+ * Once the API availible we need to change this.
2066+ * At this point we are not allowing any gap
2067+ */
2068+ continue;
2069+
2070+ SET_STREAM_DETECTED(cmd->io_request->RaidContext.raid_context_g35);
2071+ current_sd->next_seq_lba =
2072+ io_info->ldStartBlock + io_info->numBlocks;
2073+ /*
2074+ * update the mruBitMap LRU
2075+ */
2076+ shifted_values_mask =
2077+ (1 << i * BITS_PER_INDEX_STREAM) - 1;
2078+ shifted_values = ((*track_stream & shifted_values_mask)
2079+ << BITS_PER_INDEX_STREAM);
2080+ index_value_mask =
2081+ STREAM_MASK << i * BITS_PER_INDEX_STREAM;
2082+ unshifted_values =
2083+ *track_stream & ~(shifted_values_mask |
2084+ index_value_mask);
2085+ *track_stream =
2086+ unshifted_values | shifted_values | stream_num;
2087+ return;
2088+ }
2089+ }
2090+ /*
2091+ * if we did not find any stream, create a new one
2092+ * from the least recently used
2093+ */
2094+ stream_num = (*track_stream >>
2095+ ((MAX_STREAMS_TRACKED - 1) * BITS_PER_INDEX_STREAM)) &
2096+ STREAM_MASK;
2097+ current_sd = &current_ld_sd->stream_track[stream_num];
2098+ current_sd->is_read = io_info->isRead;
2099+ current_sd->next_seq_lba = io_info->ldStartBlock + io_info->numBlocks;
2100+ *track_stream = (((*track_stream & ZERO_LAST_STREAM) << 4) | stream_num);
2101+ return;
2102+}
2103+
2104+/**
2105+ * megasas_set_raidflag_cpu_affinity - This function sets the cpu
2106+ * affinity (cpu of the controller) and raid_flags in the raid context
2107+ * based on IO type.
2108+ *
2109+ * @praid_context: IO RAID context
2110+ * @raid: LD raid map
2111+ * @fp_possible: Is fast path possible?
2112+ * @is_read: Is read IO?
2113+ *
2114+ */
2115+static void
2116+megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context,
2117+ struct MR_LD_RAID *raid, bool fp_possible,
2118+ u8 is_read, u32 scsi_buff_len)
2119+{
2120+ u8 cpu_sel = MR_RAID_CTX_CPUSEL_0;
2121+ struct RAID_CONTEXT_G35 *rctx_g35;
2122+
2123+ rctx_g35 = &praid_context->raid_context_g35;
2124+ if (fp_possible) {
2125+ if (is_read) {
2126+ if ((raid->cpuAffinity.pdRead.cpu0) &&
2127+ (raid->cpuAffinity.pdRead.cpu1))
2128+ cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2129+ else if (raid->cpuAffinity.pdRead.cpu1)
2130+ cpu_sel = MR_RAID_CTX_CPUSEL_1;
2131+ } else {
2132+ if ((raid->cpuAffinity.pdWrite.cpu0) &&
2133+ (raid->cpuAffinity.pdWrite.cpu1))
2134+ cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2135+ else if (raid->cpuAffinity.pdWrite.cpu1)
2136+ cpu_sel = MR_RAID_CTX_CPUSEL_1;
2137+ /* Fast path cache by pass capable R0/R1 VD */
2138+ if ((raid->level <= 1) &&
2139+ (raid->capability.fp_cache_bypass_capable)) {
2140+ rctx_g35->routing_flags |=
2141+ (1 << MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT);
2142+ rctx_g35->raid_flags =
2143+ (MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS
2144+ << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
2145+ }
2146+ }
2147+ } else {
2148+ if (is_read) {
2149+ if ((raid->cpuAffinity.ldRead.cpu0) &&
2150+ (raid->cpuAffinity.ldRead.cpu1))
2151+ cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2152+ else if (raid->cpuAffinity.ldRead.cpu1)
2153+ cpu_sel = MR_RAID_CTX_CPUSEL_1;
2154+ } else {
2155+ if ((raid->cpuAffinity.ldWrite.cpu0) &&
2156+ (raid->cpuAffinity.ldWrite.cpu1))
2157+ cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2158+ else if (raid->cpuAffinity.ldWrite.cpu1)
2159+ cpu_sel = MR_RAID_CTX_CPUSEL_1;
2160+
2161+ if (is_stream_detected(rctx_g35) &&
2162+ (raid->level == 5) &&
2163+ (raid->writeMode == MR_RL_WRITE_THROUGH_MODE) &&
2164+ (cpu_sel == MR_RAID_CTX_CPUSEL_FCFS))
2165+ cpu_sel = MR_RAID_CTX_CPUSEL_0;
2166+ }
2167+ }
2168+
2169+ rctx_g35->routing_flags |=
2170+ (cpu_sel << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
2171+
2172+ /* Always give priority to MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2173+ * vs MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS.
2174+ * IO Subtype is not bitmap.
2175+ */
2176+ if ((raid->level == 1) && (!is_read)) {
2177+ if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)
2178+ praid_context->raid_context_g35.raid_flags =
2179+ (MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2180+ << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
2181+ }
2182+}
2183+
16902184 /**
16912185 * megasas_build_ldio_fusion - Prepares IOs to devices
16922186 * @instance: Adapter soft state
@@ -1701,29 +2195,36 @@ megasas_build_ldio_fusion(struct megasas_instance *instance, · 8 unmodified lines
17012195 struct scsi_cmnd *scp,
17022196 struct megasas_cmd_fusion *cmd)
17032197 {
1704− u8 fp_possible;
2198+ bool fp_possible;
2199+ u16 ld;
17052200 u32 start_lba_lo, start_lba_hi, device_id, datalength = 0;
2201+ u32 scsi_buff_len;
17062202 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
17072203 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
17082204 struct IO_REQUEST_INFO io_info;
17092205 struct fusion_context *fusion;
17102206 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
17112207 u8 *raidLUN;
2208+ unsigned long spinlock_flags;
2209+ union RAID_CONTEXT_UNION *praid_context;
2210+ struct MR_LD_RAID *raid = NULL;
2211+ struct MR_PRIV_DEVICE *mrdev_priv;
17122212
17132213 device_id = MEGASAS_DEV_INDEX(scp);
17142214
17152215 fusion = instance->ctrl_context;
17162216
17172217 io_request = cmd->io_request;
1718− io_request->RaidContext.VirtualDiskTgtId = cpu_to_le16(device_id);
1719− io_request->RaidContext.status = 0;
1720− io_request->RaidContext.exStatus = 0;
2218+ io_request->RaidContext.raid_context.virtual_disk_tgt_id =
2219+ cpu_to_le16(device_id);
2220+ io_request->RaidContext.raid_context.status = 0;
2221+ io_request->RaidContext.raid_context.ex_status = 0;
17212222
17222223 req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc;
17232224
17242225 start_lba_lo = 0;
17252226 start_lba_hi = 0;
1726− fp_possible = 0;
2227+ fp_possible = false;
17272228
17282229 /*
17292230 * 6-byte READ(0x08) or WRITE(0x0A) cdb
@@ -1779,22 +2280,27 @@ megasas_build_ldio_fusion(struct megasas_instance *instance, · 49 unmodified lines
17792280 io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo;
17802281 io_info.numBlocks = datalength;
17812282 io_info.ldTgtId = device_id;
1782− io_request->DataLength = cpu_to_le32(scsi_bufflen(scp));
2283+ io_info.r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
2284+ scsi_buff_len = scsi_bufflen(scp);
2285+ io_request->DataLength = cpu_to_le32(scsi_buff_len);
17832286
17842287 if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
17852288 io_info.isRead = 1;
17862289
17872290 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
2291+ ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
17882292
1789− if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >=
1790− instance->fw_supported_vd_count) || (!fusion->fast_path_io)) {
1791− io_request->RaidContext.regLockFlags = 0;
1792− fp_possible = 0;
2293+ if (ld < instance->fw_supported_vd_count)
2294+ raid = MR_LdRaidGet(ld, local_map_ptr);
2295+
2296+ if (!raid || (!fusion->fast_path_io)) {
2297+ io_request->RaidContext.raid_context.reg_lock_flags = 0;
2298+ fp_possible = false;
17932299 } else {
17942300 if (MR_BuildRaidContext(instance, &io_info,
1795− &io_request->RaidContext,
2301+ &io_request->RaidContext.raid_context,
17962302 local_map_ptr, &raidLUN))
1797− fp_possible = io_info.fpOkForIo;
2303+ fp_possible = (io_info.fpOkForIo > 0) ? true : false;
17982304 }
17992305
18002306 /* Use raw_smp_processor_id() for now until cmd->request->cpu is CPU
@@ -1803,6 +2309,54 @@ megasas_build_ldio_fusion(struct megasas_instance *instance, · 2 unmodified lines
18032309 cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ?
18042310 raw_smp_processor_id() % instance->msix_vectors : 0;
18052311
2312+ praid_context = &io_request->RaidContext;
2313+
2314+ if (instance->is_ventura) {
2315+ spin_lock_irqsave(&instance->stream_lock, spinlock_flags);
2316+ megasas_stream_detect(instance, cmd, &io_info);
2317+ spin_unlock_irqrestore(&instance->stream_lock, spinlock_flags);
2318+ /* In ventura if stream detected for a read and it is read ahead
2319+ * capable make this IO as LDIO
2320+ */
2321+ if (is_stream_detected(&io_request->RaidContext.raid_context_g35) &&
2322+ io_info.isRead && io_info.ra_capable)
2323+ fp_possible = false;
2324+
2325+ /* FP for Optimal raid level 1.
2326+ * All large RAID-1 writes (> 32 KiB, both WT and WB modes)
2327+ * are built by the driver as LD I/Os.
2328+ * All small RAID-1 WT writes (<= 32 KiB) are built as FP I/Os
2329+ * (there is never a reason to process these as buffered writes)
2330+ * All small RAID-1 WB writes (<= 32 KiB) are built as FP I/Os
2331+ * with the SLD bit asserted.
2332+ */
2333+ if (io_info.r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
2334+ mrdev_priv = scp->device->hostdata;
2335+
2336+ if (atomic_inc_return(&instance->fw_outstanding) >
2337+ (instance->host->can_queue)) {
2338+ fp_possible = false;
2339+ atomic_dec(&instance->fw_outstanding);
2340+ } else if ((scsi_buff_len > MR_LARGE_IO_MIN_SIZE) ||
2341+ atomic_dec_if_positive(&mrdev_priv->r1_ldio_hint)) {
2342+ fp_possible = false;
2343+ atomic_dec(&instance->fw_outstanding);
2344+ if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)
2345+ atomic_set(&mrdev_priv->r1_ldio_hint,
2346+ instance->r1_ldio_hint_default);
2347+ }
2348+ }
2349+
2350+ /* If raid is NULL, set CPU affinity to default CPU0 */
2351+ if (raid)
2352+ megasas_set_raidflag_cpu_affinity(praid_context,
2353+ raid, fp_possible, io_info.isRead,
2354+ scsi_buff_len);
2355+ else
2356+ praid_context->raid_context_g35.routing_flags |=
2357+ (MR_RAID_CTX_CPUSEL_0 << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
2358+ }
2359+
18062360 if (fp_possible) {
18072361 megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
18082362 local_map_ptr, start_lba_lo);
@@ -1811,29 +2365,52 @@ megasas_build_ldio_fusion(struct megasas_instance *instance, · 2 unmodified lines
18112365 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
18122366 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
18132367 if (fusion->adapter_type == INVADER_SERIES) {
1814− if (io_request->RaidContext.regLockFlags ==
2368+ if (io_request->RaidContext.raid_context.reg_lock_flags ==
18152369 REGION_TYPE_UNUSED)
18162370 cmd->request_desc->SCSIIO.RequestFlags =
18172371 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
18182372 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1819− io_request->RaidContext.Type = MPI2_TYPE_CUDA;
1820− io_request->RaidContext.nseg = 0x1;
2373+ io_request->RaidContext.raid_context.type
2374+ = MPI2_TYPE_CUDA;
2375+ io_request->RaidContext.raid_context.nseg = 0x1;
18212376 io_request->IoFlags |= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
1822− io_request->RaidContext.regLockFlags |=
2377+ io_request->RaidContext.raid_context.reg_lock_flags |=
18232378 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
18242379 MR_RL_FLAGS_SEQ_NUM_ENABLE);
2380+ } else if (instance->is_ventura) {
2381+ io_request->RaidContext.raid_context_g35.nseg_type |=
2382+ (1 << RAID_CONTEXT_NSEG_SHIFT);
2383+ io_request->RaidContext.raid_context_g35.nseg_type |=
2384+ (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
2385+ io_request->RaidContext.raid_context_g35.routing_flags |=
2386+ (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2387+ io_request->IoFlags |=
2388+ cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
18252389 }
1826− if ((fusion->load_balance_info[device_id].loadBalanceFlag) &&
1827− (io_info.isRead)) {
2390+ if (fusion->load_balance_info &&
2391+ (fusion->load_balance_info[device_id].loadBalanceFlag) &&
2392+ (io_info.isRead)) {
18282393 io_info.devHandle =
18292394 get_updated_dev_handle(instance,
18302395 &fusion->load_balance_info[device_id],
1831− &io_info);
2396+ &io_info, local_map_ptr);
18322397 scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
18332398 cmd->pd_r1_lb = io_info.pd_after_lb;
2399+ if (instance->is_ventura)
2400+ io_request->RaidContext.raid_context_g35.span_arm
2401+ = io_info.span_arm;
2402+ else
2403+ io_request->RaidContext.raid_context.span_arm
2404+ = io_info.span_arm;
2405+
18342406 } else
18352407 scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
18362408
2409+ if (instance->is_ventura)
2410+ cmd->r1_alt_dev_handle = io_info.r1_alt_dev_handle;
2411+ else
2412+ cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
2413+
18372414 if ((raidLUN[0] == 1) &&
18382415 (local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].validHandles > 1)) {
18392416 instance->dev_handle = !(instance->dev_handle);
@@ -1843,28 +2420,39 @@ megasas_build_ldio_fusion(struct megasas_instance *instance, · 3 unmodified lines
18432420
18442421 cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle;
18452422 io_request->DevHandle = io_info.devHandle;
2423+ cmd->pd_interface = io_info.pd_interface;
18462424 /* populate the LUN field */
18472425 memcpy(io_request->LUN, raidLUN, 8);
18482426 } else {
1849− io_request->RaidContext.timeoutValue =
2427+ io_request->RaidContext.raid_context.timeout_value =
18502428 cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec);
18512429 cmd->request_desc->SCSIIO.RequestFlags =
18522430 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
18532431 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
18542432 if (fusion->adapter_type == INVADER_SERIES) {
18552433 if (io_info.do_fp_rlbypass ||
1856− (io_request->RaidContext.regLockFlags == REGION_TYPE_UNUSED))
2434+ (io_request->RaidContext.raid_context.reg_lock_flags
2435+ == REGION_TYPE_UNUSED))
18572436 cmd->request_desc->SCSIIO.RequestFlags =
18582437 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
18592438 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1860− io_request->RaidContext.Type = MPI2_TYPE_CUDA;
1861− io_request->RaidContext.regLockFlags |=
2439+ io_request->RaidContext.raid_context.type
2440+ = MPI2_TYPE_CUDA;
2441+ io_request->RaidContext.raid_context.reg_lock_flags |=
18622442 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
18632443 MR_RL_FLAGS_SEQ_NUM_ENABLE);
1864− io_request->RaidContext.nseg = 0x1;
2444+ io_request->RaidContext.raid_context.nseg = 0x1;
2445+ } else if (instance->is_ventura) {
2446+ io_request->RaidContext.raid_context_g35.routing_flags |=
2447+ (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2448+ io_request->RaidContext.raid_context_g35.nseg_type |=
2449+ (1 << RAID_CONTEXT_NSEG_SHIFT);
2450+ io_request->RaidContext.raid_context_g35.nseg_type |=
2451+ (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
18652452 }
18662453 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
18672454 io_request->DevHandle = cpu_to_le16(device_id);
2455+
18682456 } /* Not FP */
18692457 }
18702458
@@ -1881,27 +2469,26 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance, · 10 unmodified lines
18812469 {
18822470 u32 device_id;
18832471 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
1884− u16 pd_index = 0;
2472+ u16 ld;
18852473 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
18862474 struct fusion_context *fusion = instance->ctrl_context;
18872475 u8 span, physArm;
18882476 __le16 devHandle;
1889− u32 ld, arRef, pd;
2477+ u32 arRef, pd;
18902478 struct MR_LD_RAID *raid;
18912479 struct RAID_CONTEXT *pRAID_Context;
18922480 u8 fp_possible = 1;
18932481
18942482 io_request = cmd->io_request;
18952483 device_id = MEGASAS_DEV_INDEX(scmd);
1896− pd_index = MEGASAS_PD_INDEX(scmd);
18972484 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
18982485 io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
18992486 /* get RAID_Context pointer */
1900− pRAID_Context = &io_request->RaidContext;
2487+ pRAID_Context = &io_request->RaidContext.raid_context;
19012488 /* Check with FW team */
1902− pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
1903− pRAID_Context->regLockRowLBA = 0;
1904− pRAID_Context->regLockLength = 0;
2489+ pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
2490+ pRAID_Context->reg_lock_row_lba = 0;
2491+ pRAID_Context->reg_lock_length = 0;
19052492
19062493 if (fusion->fast_path_io && (
19072494 device_id < instance->fw_supported_vd_count)) {
@@ -1909,10 +2496,11 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance, · 1 unmodified line
19092496 ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
19102497 if (ld >= instance->fw_supported_vd_count)
19112498 fp_possible = 0;
1912−
1913− raid = MR_LdRaidGet(ld, local_map_ptr);
1914− if (!(raid->capability.fpNonRWCapable))
1915− fp_possible = 0;
2499+ else {
2500+ raid = MR_LdRaidGet(ld, local_map_ptr);
2501+ if (!(raid->capability.fpNonRWCapable))
2502+ fp_possible = 0;
2503+ }
19162504 } else
19172505 fp_possible = 0;
19182506
@@ -1920,7 +2508,7 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance, · 1 unmodified line
19202508 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
19212509 io_request->DevHandle = cpu_to_le16(device_id);
19222510 io_request->LUN[1] = scmd->device->lun;
1923− pRAID_Context->timeoutValue =
2511+ pRAID_Context->timeout_value =
19242512 cpu_to_le16 (scmd->request->timeout / HZ);
19252513 cmd->request_desc->SCSIIO.RequestFlags =
19262514 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
@@ -1928,9 +2516,11 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance, · 1 unmodified line
19282516 } else {
19292517
19302518 /* set RAID context values */
1931− pRAID_Context->configSeqNum = raid->seqNum;
1932− pRAID_Context->regLockFlags = REGION_TYPE_SHARED_READ;
1933− pRAID_Context->timeoutValue = cpu_to_le16(raid->fpIoTimeoutForLd);
2519+ pRAID_Context->config_seq_num = raid->seqNum;
2520+ if (!instance->is_ventura)
2521+ pRAID_Context->reg_lock_flags = REGION_TYPE_SHARED_READ;
2522+ pRAID_Context->timeout_value =
2523+ cpu_to_le16(raid->fpIoTimeoutForLd);
19342524
19352525 /* get the DevHandle for the PD (since this is
19362526 fpNonRWCapable, this is a single disk RAID0) */
@@ -1965,7 +2555,8 @@ static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance, · 28 unmodified lines
19652555 */
19662556 static void
19672557 megasas_build_syspd_fusion(struct megasas_instance *instance,
1968− struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd, u8 fp_possible)
2558+ struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd,
2559+ bool fp_possible)
19692560 {
19702561 u32 device_id;
19712562 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
@@ -1975,22 +2566,25 @@ megasas_build_syspd_fusion(struct megasas_instance *instance, · 3 unmodified lines
19752566 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
19762567 struct RAID_CONTEXT *pRAID_Context;
19772568 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
2569+ struct MR_PRIV_DEVICE *mr_device_priv_data;
19782570 struct fusion_context *fusion = instance->ctrl_context;
19792571 pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id - 1) & 1];
19802572
19812573 device_id = MEGASAS_DEV_INDEX(scmd);
19822574 pd_index = MEGASAS_PD_INDEX(scmd);
19832575 os_timeout_value = scmd->request->timeout / HZ;
2576+ mr_device_priv_data = scmd->device->hostdata;
2577+ cmd->pd_interface = mr_device_priv_data->interface_type;
19842578
19852579 io_request = cmd->io_request;
19862580 /* get RAID_Context pointer */
1987− pRAID_Context = &io_request->RaidContext;
1988− pRAID_Context->regLockFlags = 0;
1989− pRAID_Context->regLockRowLBA = 0;
1990− pRAID_Context->regLockLength = 0;
2581+ pRAID_Context = &io_request->RaidContext.raid_context;
2582+ pRAID_Context->reg_lock_flags = 0;
2583+ pRAID_Context->reg_lock_row_lba = 0;
2584+ pRAID_Context->reg_lock_length = 0;
19912585 io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
19922586 io_request->LUN[1] = scmd->device->lun;
1993− pRAID_Context->RAIDFlags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
2587+ pRAID_Context->raid_flags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
19942588 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
19952589
19962590 /* If FW supports PD sequence number */
@@ -1999,24 +2593,38 @@ megasas_build_syspd_fusion(struct megasas_instance *instance, · 2 unmodified lines
19992593 /* TgtId must be incremented by 255 as jbod seq number is index
20002594 * below raid map
20012595 */
2002− pRAID_Context->VirtualDiskTgtId =
2003− cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1));
2004− pRAID_Context->configSeqNum = pd_sync->seq[pd_index].seqNum;
2596+ /* More than 256 PD/JBOD support for Ventura */
2597+ if (instance->support_morethan256jbod)
2598+ pRAID_Context->virtual_disk_tgt_id =
2599+ pd_sync->seq[pd_index].pd_target_id;
2600+ else
2601+ pRAID_Context->virtual_disk_tgt_id =
2602+ cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1));
2603+ pRAID_Context->config_seq_num = pd_sync->seq[pd_index].seqNum;
20052604 io_request->DevHandle = pd_sync->seq[pd_index].devHandle;
2006− pRAID_Context->regLockFlags |=
2007− (MR_RL_FLAGS_SEQ_NUM_ENABLE|MR_RL_FLAGS_GRANT_DESTINATION_CUDA);
2008− pRAID_Context->Type = MPI2_TYPE_CUDA;
2009− pRAID_Context->nseg = 0x1;
2605+ if (instance->is_ventura) {
2606+ io_request->RaidContext.raid_context_g35.routing_flags |=
2607+ (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2608+ io_request->RaidContext.raid_context_g35.nseg_type |=
2609+ (1 << RAID_CONTEXT_NSEG_SHIFT);
2610+ io_request->RaidContext.raid_context_g35.nseg_type |=
2611+ (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
2612+ } else {
2613+ pRAID_Context->type = MPI2_TYPE_CUDA;
2614+ pRAID_Context->nseg = 0x1;
2615+ pRAID_Context->reg_lock_flags |=
2616+ (MR_RL_FLAGS_SEQ_NUM_ENABLE|MR_RL_FLAGS_GRANT_DESTINATION_CUDA);
2617+ }
20102618 } else if (fusion->fast_path_io) {
2011− pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
2012− pRAID_Context->configSeqNum = 0;
2619+ pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
2620+ pRAID_Context->config_seq_num = 0;
20132621 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
20142622 io_request->DevHandle =
20152623 local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
20162624 } else {
20172625 /* Want to send all IO via FW path */
2018− pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
2019− pRAID_Context->configSeqNum = 0;
2626+ pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
2627+ pRAID_Context->config_seq_num = 0;
20202628 io_request->DevHandle = cpu_to_le16(0xFFFF);
20212629 }
20222630
@@ -2032,17 +2640,17 @@ megasas_build_syspd_fusion(struct megasas_instance *instance, · 9 unmodified lines
20322640 cmd->request_desc->SCSIIO.RequestFlags =
20332641 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
20342642 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2035− pRAID_Context->timeoutValue = cpu_to_le16(os_timeout_value);
2036− pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
2643+ pRAID_Context->timeout_value = cpu_to_le16(os_timeout_value);
2644+ pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
20372645 } else {
20382646 /* system pd Fast Path */
20392647 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
20402648 timeout_limit = (scmd->device->type == TYPE_DISK) ?
20412649 255 : 0xFFFF;
2042− pRAID_Context->timeoutValue =
2650+ pRAID_Context->timeout_value =
20432651 cpu_to_le16((os_timeout_value > timeout_limit) ?
20442652 timeout_limit : os_timeout_value);
2045− if (fusion->adapter_type == INVADER_SERIES)
2653+ if (fusion->adapter_type >= INVADER_SERIES)
20462654 io_request->IoFlags |=
20472655 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
20482656
@@ -2066,9 +2674,11 @@ megasas_build_io_fusion(struct megasas_instance *instance, · 17 unmodified lines
20662674 struct scsi_cmnd *scp,
20672675 struct megasas_cmd_fusion *cmd)
20682676 {
2069− u16 sge_count;
2677+ int sge_count;
20702678 u8 cmd_type;
20712679 struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
2680+ struct MR_PRIV_DEVICE *mr_device_priv_data;
2681+ mr_device_priv_data = scp->device->hostdata;
20722682
20732683 /* Zero out some fields so they don't get reused */
20742684 memset(io_request->LUN, 0x0, 8);
@@ -2078,9 +2688,9 @@ megasas_build_io_fusion(struct megasas_instance *instance, · 3 unmodified lines
20782688 io_request->Control = 0;
20792689 io_request->EEDPBlockSize = 0;
20802690 io_request->ChainOffset = 0;
2081− io_request->RaidContext.RAIDFlags = 0;
2082− io_request->RaidContext.Type = 0;
2083− io_request->RaidContext.nseg = 0;
2691+ io_request->RaidContext.raid_context.raid_flags = 0;
2692+ io_request->RaidContext.raid_context.type = 0;
2693+ io_request->RaidContext.raid_context.nseg = 0;
20842694
20852695 memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
20862696 /*
@@ -2097,12 +2707,14 @@ megasas_build_io_fusion(struct megasas_instance *instance, · 10 unmodified lines
20972707 megasas_build_ld_nonrw_fusion(instance, scp, cmd);
20982708 break;
20992709 case READ_WRITE_SYSPDIO:
2710+ megasas_build_syspd_fusion(instance, scp, cmd, true);
2711+ break;
21002712 case NON_READ_WRITE_SYSPDIO:
2101− if (instance->secure_jbod_support &&
2102− (cmd_type == NON_READ_WRITE_SYSPDIO))
2103− megasas_build_syspd_fusion(instance, scp, cmd, 0);
2713+ if (instance->secure_jbod_support ||
2714+ mr_device_priv_data->is_tm_capable)
2715+ megasas_build_syspd_fusion(instance, scp, cmd, false);
21042716 else
2105− megasas_build_syspd_fusion(instance, scp, cmd, 1);
2717+ megasas_build_syspd_fusion(instance, scp, cmd, true);
21062718 break;
21072719 default:
21082720 break;
@@ -2112,23 +2724,27 @@ megasas_build_io_fusion(struct megasas_instance *instance, · 3 unmodified lines
21122724 * Construct SGL
21132725 */
21142726
2115− sge_count =
2116− megasas_make_sgl_fusion(instance, scp,
2117− (struct MPI25_IEEE_SGE_CHAIN64 *)
2118− &io_request->SGL, cmd);
2727+ sge_count = megasas_make_sgl(instance, scp, cmd);
21192728
2120− if (sge_count > instance->max_num_sge) {
2121− dev_err(&instance->pdev->dev, "Error. sge_count (0x%x) exceeds "
2122− "max (0x%x) allowed\n", sge_count,
2123− instance->max_num_sge);
2729+ if (sge_count > instance->max_num_sge || (sge_count < 0)) {
2730+ dev_err(&instance->pdev->dev,
2731+ "%s %d sge_count (%d) is out of range. Range is: 0-%d\n",
2732+ __func__, __LINE__, sge_count, instance->max_num_sge);
21242733 return 1;
21252734 }
21262735
2127− /* numSGE store lower 8 bit of sge_count.
2128− * numSGEExt store higher 8 bit of sge_count
2129− */
2130− io_request->RaidContext.numSGE = sge_count;
2131− io_request->RaidContext.numSGEExt = (u8)(sge_count >> 8);
2736+ if (instance->is_ventura) {
2737+ set_num_sge(&io_request->RaidContext.raid_context_g35, sge_count);
2738+ cpu_to_le16s(&io_request->RaidContext.raid_context_g35.routing_flags);
2739+ cpu_to_le16s(&io_request->RaidContext.raid_context_g35.nseg_type);
2740+ } else {
2741+ /* numSGE store lower 8 bit of sge_count.
2742+ * numSGEExt store higher 8 bit of sge_count
2743+ */
2744+ io_request->RaidContext.raid_context.num_sge = sge_count;
2745+ io_request->RaidContext.raid_context.num_sge_ext =
2746+ (u8)(sge_count >> 8);
2747+ }
21322748
21332749 io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING);
21342750
@@ -2149,25 +2765,61 @@ megasas_build_io_fusion(struct megasas_instance *instance, · 14 unmodified lines
21492765 return 0;
21502766 }
21512767
2152−union MEGASAS_REQUEST_DESCRIPTOR_UNION *
2768+static union MEGASAS_REQUEST_DESCRIPTOR_UNION *
21532769 megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
21542770 {
21552771 u8 *p;
21562772 struct fusion_context *fusion;
21572773
2158− if (index >= instance->max_fw_cmds) {
2159− dev_err(&instance->pdev->dev, "Invalid SMID (0x%x)request for "
2160− "descriptor for scsi%d\n", index,
2161− instance->host->host_no);
2162− return NULL;
2163− }
21642774 fusion = instance->ctrl_context;
2165− p = fusion->req_frames_desc
2166− +sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *index;
2775+ p = fusion->req_frames_desc +
2776+ sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * index;
21672777
21682778 return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p;
21692779 }
21702780
2781+
2782+/* megasas_prepate_secondRaid1_IO
2783+ * It prepares the raid 1 second IO
2784+ */
2785+void megasas_prepare_secondRaid1_IO(struct megasas_instance *instance,
2786+ struct megasas_cmd_fusion *cmd,
2787+ struct megasas_cmd_fusion *r1_cmd)
2788+{
2789+ union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc, *req_desc2 = NULL;
2790+ struct fusion_context *fusion;
2791+ fusion = instance->ctrl_context;
2792+ req_desc = cmd->request_desc;
2793+ /* copy the io request frame as well as 8 SGEs data for r1 command*/
2794+ memcpy(r1_cmd->io_request, cmd->io_request,
2795+ (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)));
2796+ memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL,
2797+ (fusion->max_sge_in_main_msg * sizeof(union MPI2_SGE_IO_UNION)));
2798+ /*sense buffer is different for r1 command*/
2799+ r1_cmd->io_request->SenseBufferLowAddress =
2800+ cpu_to_le32(r1_cmd->sense_phys_addr);
2801+ r1_cmd->scmd = cmd->scmd;
2802+ req_desc2 = megasas_get_request_descriptor(instance,
2803+ (r1_cmd->index - 1));
2804+ req_desc2->Words = 0;
2805+ r1_cmd->request_desc = req_desc2;
2806+ req_desc2->SCSIIO.SMID = cpu_to_le16(r1_cmd->index);
2807+ req_desc2->SCSIIO.RequestFlags = req_desc->SCSIIO.RequestFlags;
2808+ r1_cmd->request_desc->SCSIIO.DevHandle = cmd->r1_alt_dev_handle;
2809+ r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle;
2810+ r1_cmd->r1_alt_dev_handle = cmd->io_request->DevHandle;
2811+ cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
2812+ cpu_to_le16(r1_cmd->index);
2813+ r1_cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
2814+ cpu_to_le16(cmd->index);
2815+ /*MSIxIndex of both commands request descriptors should be same*/
2816+ r1_cmd->request_desc->SCSIIO.MSIxIndex =
2817+ cmd->request_desc->SCSIIO.MSIxIndex;
2818+ /*span arm is different for r1 cmd*/
2819+ r1_cmd->io_request->RaidContext.raid_context_g35.span_arm =
2820+ cmd->io_request->RaidContext.raid_context_g35.span_arm + 1;
2821+}
2822+
21712823 /**
21722824 * megasas_build_and_issue_cmd_fusion -Main routine for building and
21732825 * issuing non IOCTL cmd
@@ -2178,7 +2830,7 @@ static u32 · 4 unmodified lines
21782830 megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
21792831 struct scsi_cmnd *scmd)
21802832 {
2181− struct megasas_cmd_fusion *cmd;
2833+ struct megasas_cmd_fusion *cmd, *r1_cmd = NULL;
21822834 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
21832835 u32 index;
21842836 struct fusion_context *fusion;
@@ -2193,13 +2845,22 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance, · 8 unmodified lines
21932845 return SCSI_MLQUEUE_DEVICE_BUSY;
21942846 }
21952847
2848+ if (atomic_inc_return(&instance->fw_outstanding) >
2849+ instance->host->can_queue) {
2850+ atomic_dec(&instance->fw_outstanding);
2851+ return SCSI_MLQUEUE_HOST_BUSY;
2852+ }
2853+
21962854 cmd = megasas_get_cmd_fusion(instance, scmd->request->tag);
21972855
2856+ if (!cmd) {
2857+ atomic_dec(&instance->fw_outstanding);
2858+ return SCSI_MLQUEUE_HOST_BUSY;
2859+ }
2860+
21982861 index = cmd->index;
21992862
22002863 req_desc = megasas_get_request_descriptor(instance, index-1);
2201− if (!req_desc)
2202− return SCSI_MLQUEUE_HOST_BUSY;
22032864
22042865 req_desc->Words = 0;
22052866 cmd->request_desc = req_desc;
@@ -2208,6 +2869,7 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance, · 2 unmodified lines
22082869 megasas_return_cmd_fusion(instance, cmd);
22092870 dev_err(&instance->pdev->dev, "Error building command\n");
22102871 cmd->request_desc = NULL;
2872+ atomic_dec(&instance->fw_outstanding);
22112873 return SCSI_MLQUEUE_HOST_BUSY;
22122874 }
22132875
@@ -2218,17 +2880,91 @@ megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance, · 4 unmodified lines
22182880 cmd->io_request->ChainOffset != 0xF)
22192881 dev_err(&instance->pdev->dev, "The chain offset value is not "
22202882 "correct : %x\n", cmd->io_request->ChainOffset);
2883+ /*
2884+ * if it is raid 1/10 fp write capable.
2885+ * try to get second command from pool and construct it.
2886+ * From FW, it has confirmed that lba values of two PDs
2887+ * corresponds to single R1/10 LD are always same
2888+ *
2889+ */
2890+ /* driver side count always should be less than max_fw_cmds
2891+ * to get new command
2892+ */
2893+ if (cmd->r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
2894+ r1_cmd = megasas_get_cmd_fusion(instance,
2895+ (scmd->request->tag + instance->max_fw_cmds));
2896+ megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd);
2897+ }
2898+
22212899
22222900 /*
22232901 * Issue the command to the FW
22242902 */
2225− atomic_inc(&instance->fw_outstanding);
22262903
22272904 megasas_fire_cmd_fusion(instance, req_desc);
22282905
2906+ if (r1_cmd)
2907+ megasas_fire_cmd_fusion(instance, r1_cmd->request_desc);
2908+
2909+
22292910 return 0;
22302911 }
22312912
2913+/**
2914+ * megasas_complete_r1_command -
2915+ * completes R1 FP write commands which has valid peer smid
2916+ * @instance: Adapter soft state
2917+ * @cmd_fusion: MPT command frame
2918+ *
2919+ */
2920+static inline void
2921+megasas_complete_r1_command(struct megasas_instance *instance,
2922+ struct megasas_cmd_fusion *cmd)
2923+{
2924+ u8 *sense, status, ex_status;
2925+ u32 data_length;
2926+ u16 peer_smid;
2927+ struct fusion_context *fusion;
2928+ struct megasas_cmd_fusion *r1_cmd = NULL;
2929+ struct scsi_cmnd *scmd_local = NULL;
2930+ struct RAID_CONTEXT_G35 *rctx_g35;
2931+
2932+ rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35;
2933+ fusion = instance->ctrl_context;
2934+ peer_smid = le16_to_cpu(rctx_g35->smid.peer_smid);
2935+
2936+ r1_cmd = fusion->cmd_list[peer_smid - 1];
2937+ scmd_local = cmd->scmd;
2938+ status = rctx_g35->status;
2939+ ex_status = rctx_g35->ex_status;
2940+ data_length = cmd->io_request->DataLength;
2941+ sense = cmd->sense;
2942+
2943+ cmd->cmd_completed = true;
2944+
2945+ /* Check if peer command is completed or not*/
2946+ if (r1_cmd->cmd_completed) {
2947+ rctx_g35 = &r1_cmd->io_request->RaidContext.raid_context_g35;
2948+ if (rctx_g35->status != MFI_STAT_OK) {
2949+ status = rctx_g35->status;
2950+ ex_status = rctx_g35->ex_status;
2951+ data_length = r1_cmd->io_request->DataLength;
2952+ sense = r1_cmd->sense;
2953+ }
2954+
2955+ megasas_return_cmd_fusion(instance, r1_cmd);
2956+ map_cmd_status(fusion, scmd_local, status, ex_status,
2957+ le32_to_cpu(data_length), sense);
2958+ if (instance->ldio_threshold &&
2959+ megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
2960+ atomic_dec(&instance->ldio_outstanding);
2961+ scmd_local->SCp.ptr = NULL;
2962+ megasas_return_cmd_fusion(instance, cmd);
2963+ scsi_dma_unmap(scmd_local);
2964+ scmd_local->scsi_done(scmd_local);
2965+ }
2966+}
2967+
22322968 /**
22332969 * complete_cmd_fusion - Completes command
22342970 * @instance: Adapter soft state
@@ -2244,8 +2980,8 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) · 9 unmodified lines
22442980 struct megasas_cmd *cmd_mfi;
22452981 struct megasas_cmd_fusion *cmd_fusion;
22462982 u16 smid, num_completed;
2247− u8 reply_descript_type;
2248− u32 status, extStatus, device_id;
2983+ u8 reply_descript_type, *sense, status, extStatus;
2984+ u32 device_id, data_length;
22492985 union desc_value d_val;
22502986 struct LD_LOAD_BALANCE_INFO *lbinfo;
22512987 int threshold_reply_count = 0;
@@ -2275,20 +3011,17 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) · 23 unmodified lines
22753011
22763012 while (d_val.u.low != cpu_to_le32(UINT_MAX) &&
22773013 d_val.u.high != cpu_to_le32(UINT_MAX)) {
2278− smid = le16_to_cpu(reply_desc->SMID);
22793014
3015+ smid = le16_to_cpu(reply_desc->SMID);
22803016 cmd_fusion = fusion->cmd_list[smid - 1];
2281−
2282− scsi_io_req =
2283− (struct MPI2_RAID_SCSI_IO_REQUEST *)
2284− cmd_fusion->io_request;
2285−
2286− if (cmd_fusion->scmd)
2287− cmd_fusion->scmd->SCp.ptr = NULL;
3017+ scsi_io_req = (struct MPI2_RAID_SCSI_IO_REQUEST *)
3018+ cmd_fusion->io_request;
22883019
22893020 scmd_local = cmd_fusion->scmd;
2290− status = scsi_io_req->RaidContext.status;
2291− extStatus = scsi_io_req->RaidContext.exStatus;
3021+ status = scsi_io_req->RaidContext.raid_context.status;
3022+ extStatus = scsi_io_req->RaidContext.raid_context.ex_status;
3023+ sense = cmd_fusion->sense;
3024+ data_length = scsi_io_req->DataLength;
22923025
22933026 switch (scsi_io_req->Function) {
22943027 case MPI2_FUNCTION_SCSI_TASK_MGMT:
@@ -2303,37 +3036,33 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) · 8 unmodified lines
23033036 break;
23043037 case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/
23053038 /* Update load balancing info */
2306− device_id = MEGASAS_DEV_INDEX(scmd_local);
2307− lbinfo = &fusion->load_balance_info[device_id];
2308− if (cmd_fusion->scmd->SCp.Status &
2309− MEGASAS_LOAD_BALANCE_FLAG) {
3039+ if (fusion->load_balance_info &&
3040+ (cmd_fusion->scmd->SCp.Status &
3041+ MEGASAS_LOAD_BALANCE_FLAG)) {
3042+ device_id = MEGASAS_DEV_INDEX(scmd_local);
3043+ lbinfo = &fusion->load_balance_info[device_id];
23103044 atomic_dec(&lbinfo->scsi_pending_cmds[cmd_fusion->pd_r1_lb]);
2311− cmd_fusion->scmd->SCp.Status &=
2312− ~MEGASAS_LOAD_BALANCE_FLAG;
3045+ cmd_fusion->scmd->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
23133046 }
2314− if (reply_descript_type ==
2315− MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) {
2316− if (megasas_dbg_lvl == 5)
2317− dev_err(&instance->pdev->dev, "\nFAST Path "
2318− "IO Success\n");
2319− }
2320− /* Fall thru and complete IO */
3047+ //Fall thru and complete IO
23213048 case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */
2322− /* Map the FW Cmd Status */
2323− map_cmd_status(cmd_fusion, status, extStatus);
2324− scsi_io_req->RaidContext.status = 0;
2325− scsi_io_req->RaidContext.exStatus = 0;
2326− if (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
2327− atomic_dec(&instance->ldio_outstanding);
2328− megasas_return_cmd_fusion(instance, cmd_fusion);
2329− scsi_dma_unmap(scmd_local);
2330− scmd_local->scsi_done(scmd_local);
23313049 atomic_dec(&instance->fw_outstanding);
2332−
3050+ if (cmd_fusion->r1_alt_dev_handle == MR_DEVHANDLE_INVALID) {
3051+ map_cmd_status(fusion, scmd_local, status,
3052+ extStatus, le32_to_cpu(data_length),
3053+ sense);
3054+ if (instance->ldio_threshold &&
3055+ (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO))
3056+ atomic_dec(&instance->ldio_outstanding);
3057+ scmd_local->SCp.ptr = NULL;
3058+ megasas_return_cmd_fusion(instance, cmd_fusion);
3059+ scsi_dma_unmap(scmd_local);
3060+ scmd_local->scsi_done(scmd_local);
3061+ } else /* Optimal VD - R1 FP command completion. */
3062+ megasas_complete_r1_command(instance, cmd_fusion);
23333063 break;
23343064 case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */
23353065 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
2336−
23373066 /* Poll mode. Dummy free.
23383067 * In case of Interrupt mode, caller has reverse check.
23393068 */
@@ -2376,7 +3105,7 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) · 36 unmodified lines
23763105 * pending to be completed
23773106 */
23783107 if (threshold_reply_count >= THRESHOLD_REPLY_COUNT) {
2379− if (fusion->adapter_type == INVADER_SERIES)
3108+ if (instance->msix_combined)
23803109 writel(((MSIxIndex & 0x7) << 24) |
23813110 fusion->last_reply_idx[MSIxIndex],
23823111 instance->reply_post_host_index_addr[MSIxIndex/8]);
@@ -2392,7 +3121,7 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) · 9 unmodified lines
23923121 return IRQ_NONE;
23933122
23943123 wmb();
2395− if (fusion->adapter_type == INVADER_SERIES)
3124+ if (instance->msix_combined)
23963125 writel(((MSIxIndex & 0x7) << 24) |
23973126 fusion->last_reply_idx[MSIxIndex],
23983127 instance->reply_post_host_index_addr[MSIxIndex/8]);
@@ -2404,6 +3133,22 @@ complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) · 5 unmodified lines
24043133 return IRQ_HANDLED;
24053134 }
24063135
3136+/**
3137+ * megasas_sync_irqs - Synchronizes all IRQs owned by adapter
3138+ * @instance: Adapter soft state
3139+ */
3140+void megasas_sync_irqs(unsigned long instance_addr)
3141+{
3142+ u32 count, i;
3143+ struct megasas_instance *instance =
3144+ (struct megasas_instance *)instance_addr;
3145+
3146+ count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3147+
3148+ for (i = 0; i < count; i++)
3149+ synchronize_irq(pci_irq_vector(instance->pdev, i));
3150+}
3151+
24073152 /**
24083153 * megasas_complete_cmd_dpc_fusion - Completes command
24093154 * @instance: Adapter soft state
@@ -2489,7 +3234,7 @@ irqreturn_t megasas_isr_fusion(int irq, void *devp) · 79 unmodified lines
24893234 * mfi_cmd: megasas_cmd pointer
24903235 *
24913236 */
2492−u8
3237+void
24933238 build_mpt_mfi_pass_thru(struct megasas_instance *instance,
24943239 struct megasas_cmd *mfi_cmd)
24953240 {
@@ -2518,7 +3263,7 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance, · 22 unmodified lines
25183263
25193264 io_req = cmd->io_request;
25203265
2521− if (fusion->adapter_type == INVADER_SERIES) {
3266+ if (fusion->adapter_type >= INVADER_SERIES) {
25223267 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end =
25233268 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL;
25243269 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
@@ -2539,8 +3284,6 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance, · 14 unmodified lines
25393284 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
25403285
25413286 mpi25_ieee_chain->Length = cpu_to_le32(instance->max_chain_frame_sz);
2542−
2543− return 0;
25443287 }
25453288
25463289 /**
@@ -2552,21 +3295,14 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance, · 5 unmodified lines
25523295 union MEGASAS_REQUEST_DESCRIPTOR_UNION *
25533296 build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
25543297 {
2555− union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
3298+ union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc = NULL;
25563299 u16 index;
25573300
2558− if (build_mpt_mfi_pass_thru(instance, cmd)) {
2559− dev_err(&instance->pdev->dev, "Couldn't build MFI pass thru cmd\n");
2560− return NULL;
2561− }
2562−
3301+ build_mpt_mfi_pass_thru(instance, cmd);
25633302 index = cmd->context.smid;
25643303
25653304 req_desc = megasas_get_request_descriptor(instance, index - 1);
25663305
2567− if (!req_desc)
2568− return NULL;
2569−
25703306 req_desc->Words = 0;
25713307 req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
25723308 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
@@ -2582,21 +3318,16 @@ build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) · 9 unmodified lines
25823318 * @cmd: mfi cmd pointer
25833319 *
25843320 */
2585−int
3321+void
25863322 megasas_issue_dcmd_fusion(struct megasas_instance *instance,
25873323 struct megasas_cmd *cmd)
25883324 {
25893325 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
25903326
25913327 req_desc = build_mpt_cmd(instance, cmd);
2592− if (!req_desc) {
2593− dev_info(&instance->pdev->dev, "Failed from %s %d\n",
2594− __func__, __LINE__);
2595− return DCMD_NOT_FIRED;
2596− }
25973328
25983329 megasas_fire_cmd_fusion(instance, req_desc);
2599− return DCMD_SUCCESS;
3330+ return;
26003331 }
26013332
26023333 /**
@@ -2771,6 +3502,14 @@ int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance, · 168 unmodified lines
27713502 " will reset adapter scsi%d.\n",
27723503 instance->host->host_no);
27733504 megasas_complete_cmd_dpc_fusion((unsigned long)instance);
3505+ if (instance->requestorId && reason) {
3506+ dev_warn(&instance->pdev->dev, "SR-IOV Found FW in FAULT"
3507+ " state while polling during"
3508+ " I/O timeout handling for %d\n",
3509+ instance->host->host_no);
3510+ *convert = 1;
3511+ }
3512+
27743513 retval = 1;
27753514 goto out;
27763515 }
@@ -2790,7 +3529,7 @@ int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance, · 13 unmodified lines
27903529 }
27913530
27923531 /* If SR-IOV VF mode & I/O timeout, check for HB timeout */
2793− if (instance->requestorId && reason) {
3532+ if (instance->requestorId && (reason == SCSIIO_TIMEOUT_OCR)) {
27943533 if (instance->hb_host_mem->HB.fwCounter !=
27953534 instance->hb_host_mem->HB.driverCounter) {
27963535 instance->hb_host_mem->HB.driverCounter =
@@ -3030,12 +3769,6 @@ megasas_issue_tm(struct megasas_instance *instance, u16 device_handle, · 233 unmodified lines
30303769
30313770 req_desc = megasas_get_request_descriptor(instance,
30323771 (cmd_fusion->index - 1));
3033− if (!req_desc) {
3034− dev_err(&instance->pdev->dev, "Failed from %s %d\n",
3035− __func__, __LINE__);
3036− megasas_return_cmd(instance, cmd_mfi);
3037− return -ENOMEM;
3038− }
30393772
30403773 cmd_fusion->request_desc = req_desc;
30413774 req_desc->Words = 0;
@@ -3092,7 +3825,7 @@ megasas_issue_tm(struct megasas_instance *instance, u16 device_handle, · 50 unmodified lines
30923825 break;
30933826 else {
30943827 instance->instancet->disable_intr(instance);
3095− msleep(1000);
3828+ megasas_sync_irqs((unsigned long)instance);
30963829 megasas_complete_cmd_dpc_fusion
30973830 ((unsigned long)instance);
30983831 instance->instancet->enable_intr(instance);
@@ -3173,13 +3906,13 @@ static u16 megasas_get_tm_devhandle(struct scsi_device *sdev) · 74 unmodified lines
31733906 instance = (struct megasas_instance *)sdev->host->hostdata;
31743907 fusion = instance->ctrl_context;
31753908
3176− if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
3909+ if (!MEGASAS_IS_LOGICAL(sdev)) {
31773910 if (instance->use_seqnum_jbod_fp) {
3178− pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
3179− sdev->id;
3180− pd_sync = (void *)fusion->pd_seq_sync
3181− [(instance->pd_seq_map_id - 1) & 1];
3182− devhandle = pd_sync->seq[pd_index].devHandle;
3911+ pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL)
3912+ + sdev->id;
3913+ pd_sync = (void *)fusion->pd_seq_sync
3914+ [(instance->pd_seq_map_id - 1) & 1];
3915+ devhandle = pd_sync->seq[pd_index].devHandle;
31833916 } else
31843917 sdev_printk(KERN_ERR, sdev, "Firmware expose tmCapable"
31853918 " without JBOD MAP support from %s %d\n", __func__, __LINE__);
@@ -3212,6 +3945,9 @@ int megasas_task_abort_fusion(struct scsi_cmnd *scmd) · 26 unmodified lines
32123945 instance = (struct megasas_instance *)scmd->device->host->hostdata;
32133946 fusion = instance->ctrl_context;
32143947
3948+ scmd_printk(KERN_INFO, scmd, "task abort called for scmd(%p)\n", scmd);
3949+ scsi_print_command(scmd);
3950+
32153951 if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
32163952 dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
32173953 "SCSI host:%d\n", instance->host->host_no);
@@ -3292,6 +4028,9 @@ int megasas_reset_target_fusion(struct scsi_cmnd *scmd) · 74 unmodified lines
32924028 instance = (struct megasas_instance *)scmd->device->host->hostdata;
32934029 fusion = instance->ctrl_context;
32944030
4031+ sdev_printk(KERN_INFO, scmd->device,
4032+ "target reset called for scmd(%p)\n", scmd);
4033+
32954034 if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
32964035 dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
32974036 "SCSI host:%d\n", instance->host->host_no);
@@ -3362,7 +4101,7 @@ int megasas_check_mpio_paths(struct megasas_instance *instance, · 64 unmodified lines
33624101 struct scsi_cmnd *scmd)
33634102 {
33644103 struct megasas_instance *peer_instance = NULL;
3365− int retval = (DID_RESET << 16);
4104+ int retval = (DID_REQUEUE << 16);
33664105
33674106 if (instance->peerIsPresent) {
33684107 peer_instance = megasas_get_peer_instance(instance);
@@ -3377,9 +4116,9 @@ int megasas_check_mpio_paths(struct megasas_instance *instance, · 8 unmodified lines
33774116 /* Core fusion reset function */
33784117 int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
33794118 {
3380− int retval = SUCCESS, i, convert = 0;
4119+ int retval = SUCCESS, i, j, convert = 0;
33814120 struct megasas_instance *instance;
3382− struct megasas_cmd_fusion *cmd_fusion;
4121+ struct megasas_cmd_fusion *cmd_fusion, *r1_cmd;
33834122 struct fusion_context *fusion;
33844123 u32 abs_state, status_reg, reset_adapter;
33854124 u32 io_timeout_in_crash_mode = 0;
@@ -3440,7 +4179,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason) · 54 unmodified lines
34404179 set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
34414180 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_POLLING);
34424181 instance->instancet->disable_intr(instance);
3443− msleep(1000);
4182+ megasas_sync_irqs((unsigned long)instance);
34444183
34454184 /* First try waiting for commands to complete */
34464185 if (megasas_wait_for_outstanding_fusion(instance, reason,
@@ -3451,23 +4190,40 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason) · 4 unmodified lines
34514190 if (convert)
34524191 reason = 0;
34534192
4193+ if (megasas_dbg_lvl & OCR_LOGS)
4194+ dev_info(&instance->pdev->dev, "\nPending SCSI commands:\n");
4195+
34544196 /* Now return commands back to the OS */
34554197 for (i = 0 ; i < instance->max_scsi_cmds; i++) {
34564198 cmd_fusion = fusion->cmd_list[i];
4199+ /*check for extra commands issued by driver*/
4200+ if (instance->is_ventura) {
4201+ r1_cmd = fusion->cmd_list[i + instance->max_fw_cmds];
4202+ megasas_return_cmd_fusion(instance, r1_cmd);
4203+ }
34574204 scmd_local = cmd_fusion->scmd;
34584205 if (cmd_fusion->scmd) {
4206+ if (megasas_dbg_lvl & OCR_LOGS) {
4207+ sdev_printk(KERN_INFO,
4208+ cmd_fusion->scmd->device, "SMID: 0x%x\n",
4209+ cmd_fusion->index);
4210+ scsi_print_command(cmd_fusion->scmd);
4211+ }
4212+
34594213 scmd_local->result =
34604214 megasas_check_mpio_paths(instance,
34614215 scmd_local);
3462− if (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
4216+ if (instance->ldio_threshold &&
4217+ megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
34634218 atomic_dec(&instance->ldio_outstanding);
34644219 megasas_return_cmd_fusion(instance, cmd_fusion);
34654220 scsi_dma_unmap(scmd_local);
34664221 scmd_local->scsi_done(scmd_local);
3467− atomic_dec(&instance->fw_outstanding);
34684222 }
34694223 }
34704224
4225+ atomic_set(&instance->fw_outstanding, 0);
4226+
34714227 status_reg = instance->instancet->read_fw_status_reg(
34724228 instance->reg_set);
34734229 abs_state = status_reg & MFI_STATE_MASK;
@@ -3528,11 +4284,13 @@ transition_to_ready: · 54 unmodified lines
35284284 __func__, __LINE__);
35294285 megaraid_sas_kill_hba(instance);
35304286 retval = FAILED;
4287+ goto out;
35314288 }
35324289 /* Reset load balance info */
3533− memset(fusion->load_balance_info, 0,
3534− sizeof(struct LD_LOAD_BALANCE_INFO)
3535− *MAX_LOGICAL_DRIVES_EXT);
4290+ if (fusion->load_balance_info)
4291+ memset(fusion->load_balance_info, 0,
4292+ (sizeof(struct LD_LOAD_BALANCE_INFO) *
4293+ MAX_LOGICAL_DRIVES_EXT));
35364294
35374295 if (!megasas_get_map_info(instance))
35384296 megasas_sync_map_info(instance);
@@ -3540,7 +4298,17 @@ transition_to_ready: · 1 unmodified line
35404298 megasas_setup_jbod_map(instance);
35414299
35424300 shost_for_each_device(sdev, shost)
3543− megasas_update_sdev_properties(sdev);
4301+ megasas_set_dynamic_target_properties(sdev);
4302+
4303+ /* reset stream detection array */
4304+ if (instance->is_ventura) {
4305+ for (j = 0; j < MAX_LOGICAL_DRIVES_EXT; ++j) {
4306+ memset(fusion->stream_detect_by_ld[j],
4307+ 0, sizeof(struct LD_STREAM_DETECT));
4308+ fusion->stream_detect_by_ld[j]->mru_bit_map
4309+ = MR_STREAM_BITMAP;
4310+ }
4311+ }
35444312
35454313 clear_bit(MEGASAS_FUSION_IN_RESET,
35464314 &instance->reset_flags);
@@ -3676,6 +4444,64 @@ void megasas_fusion_ocr_wq(struct work_struct *work) · 129 unmodified lines
36764444 megasas_reset_fusion(instance->host, 0);
36774445 }
36784446
4447+/* Allocate fusion context */
4448+int
4449+megasas_alloc_fusion_context(struct megasas_instance *instance)
4450+{
4451+ struct fusion_context *fusion;
4452+
4453+ instance->ctrl_context_pages = get_order(sizeof(struct fusion_context));
4454+ instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
4455+ instance->ctrl_context_pages);
4456+ if (!instance->ctrl_context) {
4457+ /* fall back to using vmalloc for fusion_context */
4458+ instance->ctrl_context = vzalloc(sizeof(struct fusion_context));
4459+ if (!instance->ctrl_context) {
4460+ dev_err(&instance->pdev->dev, "Failed from %s %d\n", __func__, __LINE__);
4461+ return -ENOMEM;
4462+ }
4463+ }
4464+
4465+ fusion = instance->ctrl_context;
4466+
4467+ fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
4468+ sizeof(struct LD_LOAD_BALANCE_INFO));
4469+ fusion->load_balance_info =
4470+ (struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
4471+ fusion->load_balance_info_pages);
4472+ if (!fusion->load_balance_info) {
4473+ fusion->load_balance_info = vzalloc(MAX_LOGICAL_DRIVES_EXT *
4474+ sizeof(struct LD_LOAD_BALANCE_INFO));
4475+ if (!fusion->load_balance_info)
4476+ dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, "
4477+ "continuing without Load Balance support\n");
4478+ }
4479+
4480+ return 0;
4481+}
4482+
4483+void
4484+megasas_free_fusion_context(struct megasas_instance *instance)
4485+{
4486+ struct fusion_context *fusion = instance->ctrl_context;
4487+
4488+ if (fusion) {
4489+ if (fusion->load_balance_info) {
4490+ if (is_vmalloc_addr(fusion->load_balance_info))
4491+ vfree(fusion->load_balance_info);
4492+ else
4493+ free_pages((ulong)fusion->load_balance_info,
4494+ fusion->load_balance_info_pages);
4495+ }
4496+
4497+ if (is_vmalloc_addr(fusion))
4498+ vfree(fusion);
4499+ else
4500+ free_pages((ulong)fusion,
4501+ instance->ctrl_context_pages);
4502+ }
4503+}
4504+
36794505 struct megasas_instance_template megasas_instance_template_fusion = {
36804506 .enable_intr = megasas_enable_intr_fusion,
36814507 .disable_intr = megasas_disable_intr_fusion,
drivers/scsi/megaraid/megaraid_sas_fusion.h+376−36
@@ -59,6 +59,8 @@ · 58 unmodified lines
5959 #define MR_RL_FLAGS_GRANT_DESTINATION_CPU1 0x10
6060 #define MR_RL_FLAGS_GRANT_DESTINATION_CUDA 0x80
6161 #define MR_RL_FLAGS_SEQ_NUM_ENABLE 0x8
62+#define MR_RL_WRITE_THROUGH_MODE 0x00
63+#define MR_RL_WRITE_BACK_MODE 0x01
6264
6365 /* T10 PI defines */
6466 #define MR_PROT_INFO_TYPE_CONTROLLER 0x8
@@ -81,6 +83,11 @@ · 16 unmodified lines
8183 enum MR_RAID_FLAGS_IO_SUB_TYPE {
8284 MR_RAID_FLAGS_IO_SUB_TYPE_NONE = 0,
8385 MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD = 1,
86+ MR_RAID_FLAGS_IO_SUB_TYPE_RMW_DATA = 2,
87+ MR_RAID_FLAGS_IO_SUB_TYPE_RMW_P = 3,
88+ MR_RAID_FLAGS_IO_SUB_TYPE_RMW_Q = 4,
89+ MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS = 6,
90+ MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT = 7
8491 };
8592
8693 /*
@@ -94,11 +101,13 @@ enum MR_RAID_FLAGS_IO_SUB_TYPE { · 7 unmodified lines
94101 #define MEGASAS_FP_CMD_LEN 16
95102 #define MEGASAS_FUSION_IN_RESET 0
96103 #define THRESHOLD_REPLY_COUNT 50
104+#define RAID_1_PEER_CMDS 2
97105 #define JBOD_MAPS_COUNT 2
98106
99107 enum MR_FUSION_ADAPTER_TYPE {
100108 THUNDERBOLT_SERIES = 0,
101109 INVADER_SERIES = 1,
110+ VENTURA_SERIES = 2,
102111 };
103112
104113 /*
@@ -108,29 +117,133 @@ enum MR_FUSION_ADAPTER_TYPE { · 3 unmodified lines
108117
109118 struct RAID_CONTEXT {
110119 #if defined(__BIG_ENDIAN_BITFIELD)
111− u8 nseg:4;
112− u8 Type:4;
120+ u8 nseg:4;
121+ u8 type:4;
113122 #else
114− u8 Type:4;
115− u8 nseg:4;
123+ u8 type:4;
124+ u8 nseg:4;
116125 #endif
117− u8 resvd0;
118− __le16 timeoutValue;
119− u8 regLockFlags;
120− u8 resvd1;
121− __le16 VirtualDiskTgtId;
122− __le64 regLockRowLBA;
123− __le32 regLockLength;
124− __le16 nextLMId;
125− u8 exStatus;
126− u8 status;
127− u8 RAIDFlags;
128− u8 numSGE;
129− __le16 configSeqNum;
130− u8 spanArm;
131− u8 priority;
132− u8 numSGEExt;
133− u8 resvd2;
126+ u8 resvd0;
127+ __le16 timeout_value;
128+ u8 reg_lock_flags;
129+ u8 resvd1;
130+ __le16 virtual_disk_tgt_id;
131+ __le64 reg_lock_row_lba;
132+ __le32 reg_lock_length;
133+ __le16 next_lmid;
134+ u8 ex_status;
135+ u8 status;
136+ u8 raid_flags;
137+ u8 num_sge;
138+ __le16 config_seq_num;
139+ u8 span_arm;
140+ u8 priority;
141+ u8 num_sge_ext;
142+ u8 resvd2;
143+};
144+
145+/*
146+ * Raid Context structure which describes ventura MegaRAID specific
147+ * IO Paramenters ,This resides at offset 0x60 where the SGL normally
148+ * starts in MPT IO Frames
149+ */
150+struct RAID_CONTEXT_G35 {
151+ #define RAID_CONTEXT_NSEG_MASK 0x00F0
152+ #define RAID_CONTEXT_NSEG_SHIFT 4
153+ #define RAID_CONTEXT_TYPE_MASK 0x000F
154+ #define RAID_CONTEXT_TYPE_SHIFT 0
155+ u16 nseg_type;
156+ u16 timeout_value; /* 0x02 -0x03 */
157+ u16 routing_flags; // 0x04 -0x05 routing flags
158+ u16 virtual_disk_tgt_id; /* 0x06 -0x07 */
159+ u64 reg_lock_row_lba; /* 0x08 - 0x0F */
160+ u32 reg_lock_length; /* 0x10 - 0x13 */
161+ union {
162+ u16 next_lmid; /* 0x14 - 0x15 */
163+ u16 peer_smid; /* used for the raid 1/10 fp writes */
164+ } smid;
165+ u8 ex_status; /* 0x16 : OUT */
166+ u8 status; /* 0x17 status */
167+ u8 raid_flags; /* 0x18 resvd[7:6], ioSubType[5:4],
168+ * resvd[3:1], preferredCpu[0]
169+ */
170+ u8 span_arm; /* 0x1C span[7:5], arm[4:0] */
171+ u16 config_seq_num; /* 0x1A -0x1B */
172+ union {
173+ /*
174+ * Bit format:
175+ * ---------------------------------
176+ * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
177+ * ---------------------------------
178+ * Byte0 | numSGE[7]- numSGE[0] |
179+ * ---------------------------------
180+ * Byte1 |SD | resvd | numSGE 8-11 |
181+ * --------------------------------
182+ */
183+ #define NUM_SGE_MASK_LOWER 0xFF
184+ #define NUM_SGE_MASK_UPPER 0x0F
185+ #define NUM_SGE_SHIFT_UPPER 8
186+ #define STREAM_DETECT_SHIFT 7
187+ #define STREAM_DETECT_MASK 0x80
188+ struct {
189+#if defined(__BIG_ENDIAN_BITFIELD) /* 0x1C - 0x1D */
190+ u16 stream_detected:1;
191+ u16 reserved:3;
192+ u16 num_sge:12;
193+#else
194+ u16 num_sge:12;
195+ u16 reserved:3;
196+ u16 stream_detected:1;
197+#endif
198+ } bits;
199+ u8 bytes[2];
200+ } u;
201+ u8 resvd2[2]; /* 0x1E-0x1F */
202+};
203+
204+#define MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT 1
205+#define MR_RAID_CTX_ROUTINGFLAGS_C2D_SHIFT 2
206+#define MR_RAID_CTX_ROUTINGFLAGS_FWD_SHIFT 3
207+#define MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT 4
208+#define MR_RAID_CTX_ROUTINGFLAGS_SBS_SHIFT 5
209+#define MR_RAID_CTX_ROUTINGFLAGS_RW_SHIFT 6
210+#define MR_RAID_CTX_ROUTINGFLAGS_LOG_SHIFT 7
211+#define MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT 8
212+#define MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_MASK 0x0F00
213+#define MR_RAID_CTX_ROUTINGFLAGS_SETDIVERT_SHIFT 12
214+#define MR_RAID_CTX_ROUTINGFLAGS_SETDIVERT_MASK 0xF000
215+
216+static inline void set_num_sge(struct RAID_CONTEXT_G35 *rctx_g35,
217+ u16 sge_count)
218+{
219+ rctx_g35->u.bytes[0] = (u8)(sge_count & NUM_SGE_MASK_LOWER);
220+ rctx_g35->u.bytes[1] |= (u8)((sge_count >> NUM_SGE_SHIFT_UPPER)
221+ & NUM_SGE_MASK_UPPER);
222+}
223+
224+static inline u16 get_num_sge(struct RAID_CONTEXT_G35 *rctx_g35)
225+{
226+ u16 sge_count;
227+
228+ sge_count = (u16)(((rctx_g35->u.bytes[1] & NUM_SGE_MASK_UPPER)
229+ << NUM_SGE_SHIFT_UPPER) | (rctx_g35->u.bytes[0]));
230+ return sge_count;
231+}
232+
233+#define SET_STREAM_DETECTED(rctx_g35) \
234+ (rctx_g35.u.bytes[1] |= STREAM_DETECT_MASK)
235+
236+#define CLEAR_STREAM_DETECTED(rctx_g35) \
237+ (rctx_g35.u.bytes[1] &= ~(STREAM_DETECT_MASK))
238+
239+static inline bool is_stream_detected(struct RAID_CONTEXT_G35 *rctx_g35)
240+{
241+ return ((rctx_g35->u.bytes[1] & STREAM_DETECT_MASK));
242+}
243+
244+union RAID_CONTEXT_UNION {
245+ struct RAID_CONTEXT raid_context;
246+ struct RAID_CONTEXT_G35 raid_context_g35;
134247 };
135248
136249 #define RAID_CTX_SPANARM_ARM_SHIFT (0)
@@ -139,6 +252,14 @@ struct RAID_CONTEXT { · 2 unmodified lines
139252 #define RAID_CTX_SPANARM_SPAN_SHIFT (5)
140253 #define RAID_CTX_SPANARM_SPAN_MASK (0xE0)
141254
255+/* number of bits per index in U32 TrackStream */
256+#define BITS_PER_INDEX_STREAM 4
257+#define INVALID_STREAM_NUM 16
258+#define MR_STREAM_BITMAP 0x76543210
259+#define STREAM_MASK ((1 << BITS_PER_INDEX_STREAM) - 1)
260+#define ZERO_LAST_STREAM 0x0fffffff
261+#define MAX_STREAMS_TRACKED 8
262+
142263 /*
143264 * define region lock types
144265 */
@@ -175,6 +296,8 @@ enum REGION_TYPE { · 30 unmodified lines
175296 #define MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG (0x0200)
176297 #define MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD (0x0100)
177298 #define MPI2_SCSIIO_EEDPFLAGS_INSERT_OP (0x0004)
299+/* EEDP escape mode */
300+#define MPI25_SCSIIO_EEDPFLAGS_DO_NOT_DISABLE_MODE (0x0040)
178301 #define MPI2_FUNCTION_SCSI_IO_REQUEST (0x00) /* SCSI IO */
179302 #define MPI2_FUNCTION_SCSI_TASK_MGMT (0x01)
180303 #define MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY (0x03)
@@ -407,7 +530,7 @@ struct MPI2_RAID_SCSI_IO_REQUEST { · 226 unmodified lines
407530 u8 LUN[8]; /* 0x34 */
408531 __le32 Control; /* 0x3C */
409532 union MPI2_SCSI_IO_CDB_UNION CDB; /* 0x40 */
410− struct RAID_CONTEXT RaidContext; /* 0x60 */
533+ union RAID_CONTEXT_UNION RaidContext; /* 0x60 */
411534 union MPI2_SGE_IO_UNION SGL; /* 0x80 */
412535 };
413536
@@ -563,7 +686,7 @@ struct MPI2_IOC_INIT_REQUEST { · 149 unmodified lines
563686 __le16 HeaderVersion; /* 0x0E */
564687 u32 Reserved5; /* 0x10 */
565688 __le16 Reserved6; /* 0x14 */
566− u8 Reserved7; /* 0x16 */
689+ u8 HostPageSize; /* 0x16 */
567690 u8 HostMSIxVectors; /* 0x17 */
568691 __le16 Reserved8; /* 0x18 */
569692 __le16 SystemRequestFrameSize; /* 0x1A */
@@ -579,6 +702,7 @@ struct MPI2_IOC_INIT_REQUEST { · 9 unmodified lines
579702
580703 /* mrpriv defines */
581704 #define MR_PD_INVALID 0xFFFF
705+#define MR_DEVHANDLE_INVALID 0xFFFF
582706 #define MAX_SPAN_DEPTH 8
583707 #define MAX_QUAD_DEPTH MAX_SPAN_DEPTH
584708 #define MAX_RAIDMAP_SPAN_DEPTH (MAX_SPAN_DEPTH)
@@ -586,16 +710,20 @@ struct MPI2_IOC_INIT_REQUEST { · 1 unmodified line
586710 #define MAX_RAIDMAP_ROW_SIZE (MAX_ROW_SIZE)
587711 #define MAX_LOGICAL_DRIVES 64
588712 #define MAX_LOGICAL_DRIVES_EXT 256
713+#define MAX_LOGICAL_DRIVES_DYN 512
589714 #define MAX_RAIDMAP_LOGICAL_DRIVES (MAX_LOGICAL_DRIVES)
590715 #define MAX_RAIDMAP_VIEWS (MAX_LOGICAL_DRIVES)
591716 #define MAX_ARRAYS 128
592717 #define MAX_RAIDMAP_ARRAYS (MAX_ARRAYS)
593718 #define MAX_ARRAYS_EXT 256
594719 #define MAX_API_ARRAYS_EXT (MAX_ARRAYS_EXT)
720+#define MAX_API_ARRAYS_DYN 512
595721 #define MAX_PHYSICAL_DEVICES 256
596722 #define MAX_RAIDMAP_PHYSICAL_DEVICES (MAX_PHYSICAL_DEVICES)
723+#define MAX_RAIDMAP_PHYSICAL_DEVICES_DYN 512
597724 #define MR_DCMD_LD_MAP_GET_INFO 0x0300e101
598725 #define MR_DCMD_SYSTEM_PD_MAP_GET_INFO 0x0200e102
726+#define MR_DCMD_DRV_GET_TARGET_PROP 0x0200e103
599727 #define MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC 0x010e8485 /* SR-IOV HB alloc*/
600728 #define MR_DCMD_LD_VF_MAP_GET_ALL_LDS_111 0x03200200
601729 #define MR_DCMD_LD_VF_MAP_GET_ALL_LDS 0x03150200
@@ -603,7 +731,7 @@ struct MPI2_IOC_INIT_REQUEST { · 1 unmodified line
603731 struct MR_DEV_HANDLE_INFO {
604732 __le16 curDevHdl;
605733 u8 validHandles;
606− u8 reserved;
734+ u8 interfaceType;
607735 __le16 devHandle[2];
608736 };
609737
@@ -640,10 +768,56 @@ struct MR_SPAN_BLOCK_INFO { · 30 unmodified lines
640768 struct MR_SPAN_INFO block_span_info;
641769 };
642770
771+#define MR_RAID_CTX_CPUSEL_0 0
772+#define MR_RAID_CTX_CPUSEL_1 1
773+#define MR_RAID_CTX_CPUSEL_2 2
774+#define MR_RAID_CTX_CPUSEL_3 3
775+#define MR_RAID_CTX_CPUSEL_FCFS 0xF
776+
777+struct MR_CPU_AFFINITY_MASK {
778+ union {
779+ struct {
780+#ifndef MFI_BIG_ENDIAN
781+ u8 hw_path:1;
782+ u8 cpu0:1;
783+ u8 cpu1:1;
784+ u8 cpu2:1;
785+ u8 cpu3:1;
786+ u8 reserved:3;
787+#else
788+ u8 reserved:3;
789+ u8 cpu3:1;
790+ u8 cpu2:1;
791+ u8 cpu1:1;
792+ u8 cpu0:1;
793+ u8 hw_path:1;
794+#endif
795+ };
796+ u8 core_mask;
797+ };
798+};
799+
800+struct MR_IO_AFFINITY {
801+ union {
802+ struct {
803+ struct MR_CPU_AFFINITY_MASK pdRead;
804+ struct MR_CPU_AFFINITY_MASK pdWrite;
805+ struct MR_CPU_AFFINITY_MASK ldRead;
806+ struct MR_CPU_AFFINITY_MASK ldWrite;
807+ };
808+ u32 word;
809+ };
810+ u8 maxCores; /* Total cores + HW Path in ROC */
811+ u8 reserved[3];
812+};
813+
643814 struct MR_LD_RAID {
644815 struct {
645816 #if defined(__BIG_ENDIAN_BITFIELD)
646− u32 reserved4:5;
817+ u32 reserved4:2;
818+ u32 fp_cache_bypass_capable:1;
819+ u32 fp_rmw_capable:1;
820+ u32 disable_coalescing:1;
647821 u32 fpBypassRegionLock:1;
648822 u32 tmCapable:1;
649823 u32 fpNonRWCapable:1;
@@ -654,11 +828,13 @@ struct MR_LD_RAID { · 4 unmodified lines
654828 u32 encryptionType:8;
655829 u32 pdPiMode:4;
656830 u32 ldPiMode:4;
657− u32 reserved5:3;
831+ u32 reserved5:2;
832+ u32 ra_capable:1;
658833 u32 fpCapable:1;
659834 #else
660835 u32 fpCapable:1;
661− u32 reserved5:3;
836+ u32 ra_capable:1;
837+ u32 reserved5:2;
662838 u32 ldPiMode:4;
663839 u32 pdPiMode:4;
664840 u32 encryptionType:8;
@@ -669,7 +845,10 @@ struct MR_LD_RAID { · 4 unmodified lines
669845 u32 fpNonRWCapable:1;
670846 u32 tmCapable:1;
671847 u32 fpBypassRegionLock:1;
672− u32 reserved4:5;
848+ u32 disable_coalescing:1;
849+ u32 fp_rmw_capable:1;
850+ u32 fp_cache_bypass_capable:1;
851+ u32 reserved4:2;
673852 #endif
674853 } capability;
675854 __le32 reserved6;
@@ -696,7 +875,36 @@ struct MR_LD_RAID { · 20 unmodified lines
696875
697876 u8 LUN[8]; /* 0x24 8 byte LUN field used for SCSI IO's */
698877 u8 fpIoTimeoutForLd;/*0x2C timeout value used by driver in FP IO*/
699− u8 reserved3[0x80-0x2D]; /* 0x2D */
878+ /* Ox2D This LD accept priority boost of this type */
879+ u8 ld_accept_priority_type;
880+ u8 reserved2[2]; /* 0x2E - 0x2F */
881+ /* 0x30 - 0x33, Logical block size for the LD */
882+ u32 logical_block_length;
883+ struct {
884+#ifndef MFI_BIG_ENDIAN
885+ /* 0x34, P_I_EXPONENT from READ CAPACITY 16 */
886+ u32 ld_pi_exp:4;
887+ /* 0x34, LOGICAL BLOCKS PER PHYSICAL
888+ * BLOCK EXPONENT from READ CAPACITY 16
889+ */
890+ u32 ld_logical_block_exp:4;
891+ u32 reserved1:24; /* 0x34 */
892+#else
893+ u32 reserved1:24; /* 0x34 */
894+ /* 0x34, LOGICAL BLOCKS PER PHYSICAL
895+ * BLOCK EXPONENT from READ CAPACITY 16
896+ */
897+ u32 ld_logical_block_exp:4;
898+ /* 0x34, P_I_EXPONENT from READ CAPACITY 16 */
899+ u32 ld_pi_exp:4;
900+#endif
901+ }; /* 0x34 - 0x37 */
902+ /* 0x38 - 0x3f, This will determine which
903+ * core will process LD IO and PD IO.
904+ */
905+ struct MR_IO_AFFINITY cpuAffinity;
906+ /* Bit definiations are specified by MR_IO_AFFINITY */
907+ u8 reserved3[0x80 - 0x40]; /* 0x40 - 0x7f */
700908 };
701909
702910 struct MR_LD_SPAN_MAP {
@@ -735,6 +943,7 @@ struct IO_REQUEST_INFO { · 32 unmodified lines
735943 u16 ldTgtId;
736944 u8 isRead;
737945 __le16 devHandle;
946+ u8 pd_interface;
738947 u64 pdBlock;
739948 u8 fpOkForIo;
740949 u8 IoforUnevenSpan;
@@ -743,6 +952,8 @@ struct IO_REQUEST_INFO { · 2 unmodified lines
743952 u64 start_row;
744953 u8 span_arm; /* span[7:5], arm[4:0] */
745954 u8 pd_after_lb;
955+ u16 r1_alt_dev_handle; /* raid 1/10 only */
956+ bool ra_capable;
746957 };
747958
748959 struct MR_LD_TARGET_SYNC {
@@ -751,6 +962,91 @@ struct MR_LD_TARGET_SYNC { · 2 unmodified lines
751962 __le16 seqNum;
752963 };
753964
965+/*
966+ * RAID Map descriptor Types.
967+ * Each element should uniquely idetify one data structure in the RAID map
968+ */
969+enum MR_RAID_MAP_DESC_TYPE {
970+ /* MR_DEV_HANDLE_INFO data */
971+ RAID_MAP_DESC_TYPE_DEVHDL_INFO = 0x0,
972+ /* target to Ld num Index map */
973+ RAID_MAP_DESC_TYPE_TGTID_INFO = 0x1,
974+ /* MR_ARRAY_INFO data */
975+ RAID_MAP_DESC_TYPE_ARRAY_INFO = 0x2,
976+ /* MR_LD_SPAN_MAP data */
977+ RAID_MAP_DESC_TYPE_SPAN_INFO = 0x3,
978+ RAID_MAP_DESC_TYPE_COUNT,
979+};
980+
981+/*
982+ * This table defines the offset, size and num elements of each descriptor
983+ * type in the RAID Map buffer
984+ */
985+struct MR_RAID_MAP_DESC_TABLE {
986+ /* Raid map descriptor type */
987+ u32 raid_map_desc_type;
988+ /* Offset into the RAID map buffer where
989+ * descriptor data is saved
990+ */
991+ u32 raid_map_desc_offset;
992+ /* total size of the
993+ * descriptor buffer
994+ */
995+ u32 raid_map_desc_buffer_size;
996+ /* Number of elements contained in the
997+ * descriptor buffer
998+ */
999+ u32 raid_map_desc_elements;
1000+};
1001+
1002+/*
1003+ * Dynamic Raid Map Structure.
1004+ */
1005+struct MR_FW_RAID_MAP_DYNAMIC {
1006+ u32 raid_map_size; /* total size of RAID Map structure */
1007+ u32 desc_table_offset;/* Offset of desc table into RAID map*/
1008+ u32 desc_table_size; /* Total Size of desc table */
1009+ /* Total Number of elements in the desc table */
1010+ u32 desc_table_num_elements;
1011+ u64 reserved1;
1012+ u32 reserved2[3]; /*future use */
1013+ /* timeout value used by driver in FP IOs */
1014+ u8 fp_pd_io_timeout_sec;
1015+ u8 reserved3[3];
1016+ /* when this seqNum increments, driver needs to
1017+ * release RMW buffers asap
1018+ */
1019+ u32 rmw_fp_seq_num;
1020+ u16 ld_count; /* count of lds. */
1021+ u16 ar_count; /* count of arrays */
1022+ u16 span_count; /* count of spans */
1023+ u16 reserved4[3];
1024+/*
1025+ * The below structure of pointers is only to be used by the driver.
1026+ * This is added in the ,API to reduce the amount of code changes
1027+ * needed in the driver to support dynamic RAID map Firmware should
1028+ * not update these pointers while preparing the raid map
1029+ */
1030+ union {
1031+ struct {
1032+ struct MR_DEV_HANDLE_INFO *dev_hndl_info;
1033+ u16 *ld_tgt_id_to_ld;
1034+ struct MR_ARRAY_INFO *ar_map_info;
1035+ struct MR_LD_SPAN_MAP *ld_span_map;
1036+ };
1037+ u64 ptr_structure_size[RAID_MAP_DESC_TYPE_COUNT];
1038+ };
1039+/*
1040+ * RAID Map descriptor table defines the layout of data in the RAID Map.
1041+ * The size of the descriptor table itself could change.
1042+ */
1043+ /* Variable Size descriptor Table. */
1044+ struct MR_RAID_MAP_DESC_TABLE
1045+ raid_map_desc_table[RAID_MAP_DESC_TYPE_COUNT];
1046+ /* Variable Size buffer containing all data */
1047+ u32 raid_map_desc_data[1];
1048+}; /* Dynamicaly sized RAID MAp structure */
1049+
7541050 #define IEEE_SGE_FLAGS_ADDR_MASK (0x03)
7551051 #define IEEE_SGE_FLAGS_SYSTEM_ADDR (0x00)
7561052 #define IEEE_SGE_FLAGS_IOCDDR_ADDR (0x01)
@@ -759,6 +1055,16 @@ struct MR_LD_TARGET_SYNC { · 2 unmodified lines
7591055 #define IEEE_SGE_FLAGS_CHAIN_ELEMENT (0x80)
7601056 #define IEEE_SGE_FLAGS_END_OF_LIST (0x40)
7611057
1058+#define MPI2_SGE_FLAGS_SHIFT (0x02)
1059+#define IEEE_SGE_FLAGS_FORMAT_MASK (0xC0)
1060+#define IEEE_SGE_FLAGS_FORMAT_IEEE (0x00)
1061+#define IEEE_SGE_FLAGS_FORMAT_NVME (0x02)
1062+
1063+#define MPI26_IEEE_SGE_FLAGS_NSF_MASK (0x1C)
1064+#define MPI26_IEEE_SGE_FLAGS_NSF_MPI_IEEE (0x00)
1065+#define MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP (0x08)
1066+#define MPI26_IEEE_SGE_FLAGS_NSF_NVME_SGL (0x10)
1067+
7621068 struct megasas_register_set;
7631069 struct megasas_instance;
7641070
@@ -795,6 +1101,10 @@ struct megasas_cmd_fusion { · 30 unmodified lines
7951101 u32 index;
7961102 u8 pd_r1_lb;
7971103 struct completion done;
1104+ u8 pd_interface;
1105+ u16 r1_alt_dev_handle; /* raid 1/10 only*/
1106+ bool cmd_completed; /* raid 1/10 fp writes status holder */
1107+
7981108 };
7991109
8001110 struct LD_LOAD_BALANCE_INFO {
@@ -856,9 +1166,10 @@ struct MR_DRV_RAID_MAP { · 55 unmodified lines
8561166 __le16 spanCount;
8571167 __le16 reserve3;
8581168
859− struct MR_DEV_HANDLE_INFO devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES];
860− u8 ldTgtIdToLd[MAX_LOGICAL_DRIVES_EXT];
861− struct MR_ARRAY_INFO arMapInfo[MAX_API_ARRAYS_EXT];
1169+ struct MR_DEV_HANDLE_INFO
1170+ devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES_DYN];
1171+ u16 ldTgtIdToLd[MAX_LOGICAL_DRIVES_DYN];
1172+ struct MR_ARRAY_INFO arMapInfo[MAX_API_ARRAYS_DYN];
8621173 struct MR_LD_SPAN_MAP ldSpanMap[1];
8631174
8641175 };
@@ -870,7 +1181,7 @@ struct MR_DRV_RAID_MAP { · 5 unmodified lines
8701181 struct MR_DRV_RAID_MAP_ALL {
8711182
8721183 struct MR_DRV_RAID_MAP raidMap;
873− struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_EXT - 1];
1184+ struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN - 1];
8741185 } __packed;
8751186
8761187
@@ -919,7 +1230,8 @@ struct MR_PD_CFG_SEQ { · 42 unmodified lines
9191230 u8 reserved:7;
9201231 #endif
9211232 } capability;
922− u8 reserved[3];
1233+ u8 reserved;
1234+ u16 pd_target_id;
9231235 } __packed;
9241236
9251237 struct MR_PD_CFG_SEQ_NUM_SYNC {
@@ -928,6 +1240,30 @@ struct MR_PD_CFG_SEQ_NUM_SYNC { · 2 unmodified lines
9281240 struct MR_PD_CFG_SEQ seq[1];
9291241 } __packed;
9301242
1243+/* stream detection */
1244+struct STREAM_DETECT {
1245+ u64 next_seq_lba; /* next LBA to match sequential access */
1246+ struct megasas_cmd_fusion *first_cmd_fusion; /* first cmd in group */
1247+ struct megasas_cmd_fusion *last_cmd_fusion; /* last cmd in group */
1248+ u32 count_cmds_in_stream; /* count of host commands in this stream */
1249+ u16 num_sges_in_group; /* total number of SGEs in grouped IOs */
1250+ u8 is_read; /* SCSI OpCode for this stream */
1251+ u8 group_depth; /* total number of host commands in group */
1252+ /* TRUE if cannot add any more commands to this group */
1253+ bool group_flush;
1254+ u8 reserved[7]; /* pad to 64-bit alignment */
1255+};
1256+
1257+struct LD_STREAM_DETECT {
1258+ bool write_back; /* TRUE if WB, FALSE if WT */
1259+ bool fp_write_enabled;
1260+ bool members_ssds;
1261+ bool fp_cache_bypass_capable;
1262+ u32 mru_bit_map; /* bitmap used to track MRU and LRU stream indicies */
1263+ /* this is the array of stream detect structures (one per stream) */
1264+ struct STREAM_DETECT stream_track[MAX_STREAMS_TRACKED];
1265+};
1266+
9311267 struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY {
9321268 u64 RDPQBaseAddress;
9331269 u32 Reserved1;
@@ -965,7 +1301,7 @@ struct fusion_context { · 31 unmodified lines
9651301 u8 chain_offset_io_request;
9661302 u8 chain_offset_mfi_pthru;
9671303
968− struct MR_FW_RAID_MAP_ALL *ld_map[2];
1304+ struct MR_FW_RAID_MAP_DYNAMIC *ld_map[2];
9691305 dma_addr_t ld_map_phys[2];
9701306
9711307 /*Non dma-able memory. Driver local copy.*/
@@ -973,14 +1309,18 @@ struct fusion_context { · 1 unmodified line
9731309
9741310 u32 max_map_sz;
9751311 u32 current_map_sz;
1312+ u32 old_map_sz;
1313+ u32 new_map_sz;
9761314 u32 drv_map_sz;
9771315 u32 drv_map_pages;
9781316 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_seq_sync[JBOD_MAPS_COUNT];
9791317 dma_addr_t pd_seq_phys[JBOD_MAPS_COUNT];
9801318 u8 fast_path_io;
981− struct LD_LOAD_BALANCE_INFO load_balance_info[MAX_LOGICAL_DRIVES_EXT];
1319+ struct LD_LOAD_BALANCE_INFO *load_balance_info;
1320+ u32 load_balance_info_pages;
9821321 LD_SPAN_INFO log_to_span[MAX_LOGICAL_DRIVES_EXT];
9831322 u8 adapter_type;
1323+ struct LD_STREAM_DETECT **stream_detect_by_ld;
9841324 };
9851325
9861326 union desc_value {
drivers/scsi/mpt3sas/mpi/mpi2_ioc.h+2−0
@@ -624,6 +624,8 @@ typedef struct _MPI26_EVENT_DATA_ACTIVE_CABLE_EXCEPT { · 623 unmodified lines
624624
625625 /* defines for ReasonCode field */
626626 #define MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER (0x00)
627+#define MPI26_EVENT_ACTIVE_CABLE_PRESENT (0x01)
628+#define MPI26_EVENT_ACTIVE_CABLE_DEGRADED (0x02)
627629
628630 /*Hard Reset Received Event data */
629631
drivers/scsi/mpt3sas/mpt3sas_base.c+20−0
@@ -1040,6 +1040,25 @@ _base_interrupt(int irq, void *bus_id) · 1039 unmodified lines
10401040 reply_q->reply_post_free[reply_q->reply_post_host_index].
10411041 Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
10421042 completed_cmds++;
1043+ /* Update the reply post host index after continuously
1044+ * processing the threshold number of Reply Descriptors.
1045+ * So that FW can find enough entries to post the Reply
1046+ * Descriptors in the reply descriptor post queue.
1047+ */
1048+ if (completed_cmds > ioc->hba_queue_depth/3) {
1049+ if (ioc->combined_reply_queue) {
1050+ writel(reply_q->reply_post_host_index |
1051+ ((msix_index & 7) <<
1052+ MPI2_RPHI_MSIX_INDEX_SHIFT),
1053+ ioc->replyPostRegisterIndex[msix_index/8]);
1054+ } else {
1055+ writel(reply_q->reply_post_host_index |
1056+ (msix_index <<
1057+ MPI2_RPHI_MSIX_INDEX_SHIFT),
1058+ &ioc->chip->ReplyPostHostIndex);
1059+ }
1060+ completed_cmds = 1;
1061+ }
10431062 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
10441063 goto out;
10451064 if (!reply_q->reply_post_host_index)
@@ -5522,6 +5541,7 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc) · 4476 unmodified lines
55225541 goto out_free_resources;
55235542
55245543 ioc->non_operational_loop = 0;
5544+ ioc->got_task_abort_from_ioctl = 0;
55255545 return 0;
55265546
55275547 out_free_resources:
drivers/scsi/mpt3sas/mpt3sas_base.h+4−3
@@ -73,9 +73,9 @@ · 72 unmodified lines
7373 #define MPT3SAS_DRIVER_NAME "mpt3sas"
7474 #define MPT3SAS_AUTHOR "Avago Technologies <MPT-FusionLinux.pdl@avagotech.com>"
7575 #define MPT3SAS_DESCRIPTION "LSI MPT Fusion SAS 3.0 Device Driver"
76−#define MPT3SAS_DRIVER_VERSION "14.101.00.00"
77−#define MPT3SAS_MAJOR_VERSION 14
78−#define MPT3SAS_MINOR_VERSION 101
76+#define MPT3SAS_DRIVER_VERSION "15.100.00.00"
77+#define MPT3SAS_MAJOR_VERSION 15
78+#define MPT3SAS_MINOR_VERSION 100
7979 #define MPT3SAS_BUILD_VERSION 0
8080 #define MPT3SAS_RELEASE_VERSION 00
8181
@@ -1000,6 +1000,7 @@ struct MPT3SAS_ADAPTER { · 918 unmodified lines
10001000 u8 broadcast_aen_busy;
10011001 u16 broadcast_aen_pending;
10021002 u8 shost_recovery;
1003+ u8 got_task_abort_from_ioctl;
10031004
10041005 struct mutex reset_in_progress_mutex;
10051006 spinlock_t ioc_reset_in_progress_lock;
drivers/scsi/mpt3sas/mpt3sas_ctl.c+3−1
@@ -826,16 +826,18 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg, · 825 unmodified lines
826826 "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n",
827827 ioc->name,
828828 le16_to_cpu(tm_request->DevHandle), tm_request->TaskType));
829−
829+ ioc->got_task_abort_from_ioctl = 1;
830830 if (tm_request->TaskType ==
831831 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
832832 tm_request->TaskType ==
833833 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
834834 if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
835835 mpt3sas_base_free_smid(ioc, smid);
836+ ioc->got_task_abort_from_ioctl = 0;
836837 goto out;
837838 }
838839 }
840+ ioc->got_task_abort_from_ioctl = 0;
839841
840842 if (test_bit(device_handle, ioc->device_remove_in_progress)) {
841843 dtmprintk(ioc, pr_info(MPT3SAS_FMT
drivers/scsi/mpt3sas/mpt3sas_scsih.c+45−11
@@ -1074,6 +1074,26 @@ _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid) · 1073 unmodified lines
10741074 return ioc->scsi_lookup[smid - 1].scmd;
10751075 }
10761076
1077+/**
1078+ * __scsih_scsi_lookup_get_clear - returns scmd entry without
1079+ * holding any lock.
1080+ * @ioc: per adapter object
1081+ * @smid: system request message index
1082+ *
1083+ * Returns the smid stored scmd pointer.
1084+ * Then will dereference the stored scmd pointer.
1085+ */
1086+static inline struct scsi_cmnd *
1087+__scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc,
1088+ u16 smid)
1089+{
1090+ struct scsi_cmnd *scmd = NULL;
1091+
1092+ swap(scmd, ioc->scsi_lookup[smid - 1].scmd);
1093+
1094+ return scmd;
1095+}
1096+
10771097 /**
10781098 * _scsih_scsi_lookup_get_clear - returns scmd entry
10791099 * @ioc: per adapter object
@@ -1089,8 +1109,7 @@ _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid) · 9 unmodified lines
10891109 struct scsi_cmnd *scmd;
10901110
10911111 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1092− scmd = ioc->scsi_lookup[smid - 1].scmd;
1093− ioc->scsi_lookup[smid - 1].scmd = NULL;
1112+ scmd = __scsih_scsi_lookup_get_clear(ioc, smid);
10941113 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
10951114
10961115 return scmd;
@@ -4661,7 +4680,13 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) · 3564 unmodified lines
46614680 unsigned int sector_sz;
46624681
46634682 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4664− scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4683+
4684+ if (ioc->broadcast_aen_busy || ioc->pci_error_recovery ||
4685+ ioc->got_task_abort_from_ioctl)
4686+ scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4687+ else
4688+ scmd = __scsih_scsi_lookup_get_clear(ioc, smid);
4689+
46654690 if (scmd == NULL)
46664691 return 1;
46674692
@@ -8044,15 +8069,24 @@ mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, · 3376 unmodified lines
80448069 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
80458070 ActiveCableEventData =
80468071 (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData;
8047− if (ActiveCableEventData->ReasonCode ==
8048− MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER) {
8049− pr_info(MPT3SAS_FMT "Currently an active cable with ReceptacleID %d",
8050− ioc->name, ActiveCableEventData->ReceptacleID);
8051− pr_info("cannot be powered and devices connected to this active cable");
8052− pr_info("will not be seen. This active cable");
8053− pr_info("requires %d mW of power",
8054− ActiveCableEventData->ActiveCablePowerRequirement);
8072+ switch (ActiveCableEventData->ReasonCode) {
8073+ case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER:
8074+ pr_notice(MPT3SAS_FMT "Receptacle ID %d: This active cable"
8075+ " requires %d mW of power\n", ioc->name,
8076+ ActiveCableEventData->ReceptacleID,
8077+ ActiveCableEventData->ActiveCablePowerRequirement);
8078+ pr_notice(MPT3SAS_FMT "Receptacle ID %d: Devices connected"
8079+ " to this active cable will not be seen\n",
8080+ ioc->name, ActiveCableEventData->ReceptacleID);
8081+ break;
8082+
8083+ case MPI26_EVENT_ACTIVE_CABLE_DEGRADED:
8084+ pr_notice(MPT3SAS_FMT "ReceptacleID %d: This cable",
8085+ ioc->name, ActiveCableEventData->ReceptacleID);
8086+ pr_notice(" is not running at an optimal speed(12 Gb/s)\n");
8087+ break;
80558088 }
8089+
80568090 break;
80578091
80588092 default: /* ignore the rest */
drivers/scsi/mvumi.c+1−5
@@ -2225,15 +2225,12 @@ static struct scsi_host_template mvumi_template = { · 2224 unmodified lines
22252225 .name = "Marvell Storage Controller",
22262226 .slave_configure = mvumi_slave_configure,
22272227 .queuecommand = mvumi_queue_command,
2228+ .eh_timed_out = mvumi_timed_out,
22282229 .eh_host_reset_handler = mvumi_host_reset,
22292230 .bios_param = mvumi_bios_param,
22302231 .this_id = -1,
22312232 };
22322233
2233−static struct scsi_transport_template mvumi_transport_template = {
2234− .eh_timed_out = mvumi_timed_out,
2235−};
2236−
22372234 static int mvumi_cfg_hw_reg(struct mvumi_hba *mhba)
22382235 {
22392236 void *base = NULL;
@@ -2451,7 +2448,6 @@ static int mvumi_io_attach(struct mvumi_hba *mhba) · 211 unmodified lines
24512448 host->cmd_per_lun = (mhba->max_io - 1) ? (mhba->max_io - 1) : 1;
24522449 host->max_id = mhba->max_target_id;
24532450 host->max_cmd_len = MAX_COMMAND_SIZE;
2454− host->transportt = &mvumi_transport_template;
24552451
24562452 ret = scsi_add_host(host, &mhba->pdev->dev);
24572453 if (ret) {
drivers/scsi/pm8001/pm8001_init.c+14−21
@@ -888,7 +888,6 @@ static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha) · 887 unmodified lines
888888 u32 i = 0, j = 0;
889889 u32 number_of_intr;
890890 int flag = 0;
891− u32 max_entry;
892891 int rc;
893892 static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
894893
@@ -900,18 +899,14 @@ static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha) · 5 unmodified lines
900899 flag &= ~IRQF_SHARED;
901900 }
902901
903− max_entry = sizeof(pm8001_ha->msix_entries) /
904− sizeof(pm8001_ha->msix_entries[0]);
905− for (i = 0; i < max_entry ; i++)
906− pm8001_ha->msix_entries[i].entry = i;
907− rc = pci_enable_msix_exact(pm8001_ha->pdev, pm8001_ha->msix_entries,
908− number_of_intr);
909− pm8001_ha->number_of_intr = number_of_intr;
910− if (rc)
902+ rc = pci_alloc_irq_vectors(pm8001_ha->pdev, number_of_intr,
903+ number_of_intr, PCI_IRQ_MSIX);
904+ if (rc < 0)
911905 return rc;
906+ pm8001_ha->number_of_intr = number_of_intr;
912907
913908 PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
914− "pci_enable_msix_exact request ret:%d no of intr %d\n",
909+ "pci_alloc_irq_vectors request ret:%d no of intr %d\n",
915910 rc, pm8001_ha->number_of_intr));
916911
917912 for (i = 0; i < number_of_intr; i++) {
@@ -920,15 +915,15 @@ static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha) · 2 unmodified lines
920915 pm8001_ha->irq_vector[i].irq_id = i;
921916 pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
922917
923− rc = request_irq(pm8001_ha->msix_entries[i].vector,
918+ rc = request_irq(pci_irq_vector(pm8001_ha->pdev, i),
924919 pm8001_interrupt_handler_msix, flag,
925920 intr_drvname[i], &(pm8001_ha->irq_vector[i]));
926921 if (rc) {
927922 for (j = 0; j < i; j++) {
928− free_irq(pm8001_ha->msix_entries[j].vector,
923+ free_irq(pci_irq_vector(pm8001_ha->pdev, i),
929924 &(pm8001_ha->irq_vector[i]));
930925 }
931− pci_disable_msix(pm8001_ha->pdev);
926+ pci_free_irq_vectors(pm8001_ha->pdev);
932927 break;
933928 }
934929 }
@@ -1102,11 +1097,10 @@ static void pm8001_pci_remove(struct pci_dev *pdev) · 167 unmodified lines
11021097
11031098 #ifdef PM8001_USE_MSIX
11041099 for (i = 0; i < pm8001_ha->number_of_intr; i++)
1105− synchronize_irq(pm8001_ha->msix_entries[i].vector);
1100+ synchronize_irq(pci_irq_vector(pdev, i));
11061101 for (i = 0; i < pm8001_ha->number_of_intr; i++)
1107− free_irq(pm8001_ha->msix_entries[i].vector,
1108− &(pm8001_ha->irq_vector[i]));
1109− pci_disable_msix(pdev);
1102+ free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
1103+ pci_free_irq_vectors(pdev);
11101104 #else
11111105 free_irq(pm8001_ha->irq, sha);
11121106 #endif
@@ -1152,11 +1146,10 @@ static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state) · 39 unmodified lines
11521146 PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
11531147 #ifdef PM8001_USE_MSIX
11541148 for (i = 0; i < pm8001_ha->number_of_intr; i++)
1155− synchronize_irq(pm8001_ha->msix_entries[i].vector);
1149+ synchronize_irq(pci_irq_vector(pdev, i));
11561150 for (i = 0; i < pm8001_ha->number_of_intr; i++)
1157− free_irq(pm8001_ha->msix_entries[i].vector,
1158− &(pm8001_ha->irq_vector[i]));
1159− pci_disable_msix(pdev);
1151+ free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
1152+ pci_free_irq_vectors(pdev);
11601153 #else
11611154 free_irq(pm8001_ha->irq, sha);
11621155 #endif
drivers/scsi/pm8001/pm8001_sas.h+0−2
@@ -521,8 +521,6 @@ struct pm8001_hba_info { · 520 unmodified lines
521521 struct pm8001_device *devices;
522522 struct pm8001_ccb_info *ccb_info;
523523 #ifdef PM8001_USE_MSIX
524− struct msix_entry msix_entries[PM8001_MAX_MSIX_VEC];
525− /*for msi-x interrupt*/
526524 int number_of_intr;/*will be used in remove()*/
527525 #endif
528526 #ifdef PM8001_USE_TASKLET
drivers/scsi/pmcraid.c+41−51
@@ -4587,16 +4587,14 @@ static void pmcraid_tasklet_function(unsigned long instance) · 4586 unmodified lines
45874587 static
45884588 void pmcraid_unregister_interrupt_handler(struct pmcraid_instance *pinstance)
45894589 {
4590+ struct pci_dev *pdev = pinstance->pdev;
45904591 int i;
45914592
45924593 for (i = 0; i < pinstance->num_hrrq; i++)
4593− free_irq(pinstance->hrrq_vector[i].vector,
4594− &(pinstance->hrrq_vector[i]));
4594+ free_irq(pci_irq_vector(pdev, i), &pinstance->hrrq_vector[i]);
45954595
4596− if (pinstance->interrupt_mode) {
4597− pci_disable_msix(pinstance->pdev);
4598− pinstance->interrupt_mode = 0;
4599− }
4596+ pinstance->interrupt_mode = 0;
4597+ pci_free_irq_vectors(pdev);
46004598 }
46014599
46024600 /**
@@ -4609,60 +4607,52 @@ void pmcraid_unregister_interrupt_handler(struct pmcraid_instance *pinstance) · 6 unmodified lines
46094607 static int
46104608 pmcraid_register_interrupt_handler(struct pmcraid_instance *pinstance)
46114609 {
4612− int rc;
46134610 struct pci_dev *pdev = pinstance->pdev;
4611+ unsigned int irq_flag = PCI_IRQ_LEGACY, flag;
4612+ int num_hrrq, rc, i;
4613+ irq_handler_t isr;
46144614
4615− if ((pmcraid_enable_msix) &&
4616− (pci_find_capability(pdev, PCI_CAP_ID_MSIX))) {
4617− int num_hrrq = PMCRAID_NUM_MSIX_VECTORS;
4618− struct msix_entry entries[PMCRAID_NUM_MSIX_VECTORS];
4619− int i;
4620− for (i = 0; i < PMCRAID_NUM_MSIX_VECTORS; i++)
4621− entries[i].entry = i;
4622−
4623− num_hrrq = pci_enable_msix_range(pdev, entries, 1, num_hrrq);
4624− if (num_hrrq < 0)
4625− goto pmcraid_isr_legacy;
4626−
4627− for (i = 0; i < num_hrrq; i++) {
4628− pinstance->hrrq_vector[i].hrrq_id = i;
4629− pinstance->hrrq_vector[i].drv_inst = pinstance;
4630− pinstance->hrrq_vector[i].vector = entries[i].vector;
4631− rc = request_irq(pinstance->hrrq_vector[i].vector,
4632− pmcraid_isr_msix, 0,
4633− PMCRAID_DRIVER_NAME,
4634− &(pinstance->hrrq_vector[i]));
4635−
4636− if (rc) {
4637− int j;
4638− for (j = 0; j < i; j++)
4639− free_irq(entries[j].vector,
4640− &(pinstance->hrrq_vector[j]));
4641− pci_disable_msix(pdev);
4642− goto pmcraid_isr_legacy;
4643− }
4644− }
4615+ if (pmcraid_enable_msix)
4616+ irq_flag |= PCI_IRQ_MSIX;
46454617
4646− pinstance->num_hrrq = num_hrrq;
4618+ num_hrrq = pci_alloc_irq_vectors(pdev, 1, PMCRAID_NUM_MSIX_VECTORS,
4619+ irq_flag);
4620+ if (num_hrrq < 0)
4621+ return num_hrrq;
4622+
4623+ if (pdev->msix_enabled) {
4624+ flag = 0;
4625+ isr = pmcraid_isr_msix;
4626+ } else {
4627+ flag = IRQF_SHARED;
4628+ isr = pmcraid_isr;
4629+ }
4630+
4631+ for (i = 0; i < num_hrrq; i++) {
4632+ struct pmcraid_isr_param *vec = &pinstance->hrrq_vector[i];
4633+
4634+ vec->hrrq_id = i;
4635+ vec->drv_inst = pinstance;
4636+ rc = request_irq(pci_irq_vector(pdev, i), isr, flag,
4637+ PMCRAID_DRIVER_NAME, vec);
4638+ if (rc)
4639+ goto out_unwind;
4640+ }
4641+
4642+ pinstance->num_hrrq = num_hrrq;
4643+ if (pdev->msix_enabled) {
46474644 pinstance->interrupt_mode = 1;
46484645 iowrite32(DOORBELL_INTR_MODE_MSIX,
46494646 pinstance->int_regs.host_ioa_interrupt_reg);
46504647 ioread32(pinstance->int_regs.host_ioa_interrupt_reg);
4651− goto pmcraid_isr_out;
46524648 }
46534649
4654−pmcraid_isr_legacy:
4655− /* If MSI-X registration failed fallback to legacy mode, where
4656− * only one hrrq entry will be used
4657− */
4658− pinstance->hrrq_vector[0].hrrq_id = 0;
4659− pinstance->hrrq_vector[0].drv_inst = pinstance;
4660− pinstance->hrrq_vector[0].vector = pdev->irq;
4661− pinstance->num_hrrq = 1;
4662−
4663− rc = request_irq(pdev->irq, pmcraid_isr, IRQF_SHARED,
4664− PMCRAID_DRIVER_NAME, &pinstance->hrrq_vector[0]);
4665−pmcraid_isr_out:
4650+ return 0;
4651+
4652+out_unwind:
4653+ while (--i > 0)
4654+ free_irq(pci_irq_vector(pdev, i), &pinstance->hrrq_vector[i]);
4655+ pci_free_irq_vectors(pdev);
46664656 return rc;
46674657 }
46684658
drivers/scsi/pmcraid.h+0−1
@@ -628,7 +628,6 @@ struct pmcraid_interrupts { · 627 unmodified lines
628628 /* ISR parameters LLD allocates (one for each MSI-X if enabled) vectors */
629629 struct pmcraid_isr_param {
630630 struct pmcraid_instance *drv_inst;
631− u16 vector; /* allocated msi-x vector */
632631 u8 hrrq_id; /* hrrq entry index */
633632 };
634633
drivers/scsi/qedi/qedi_dbg.c+6−3
@@ -52,7 +52,7 @@ qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line, · 51 unmodified lines
5252 vaf.va = &va;
5353
5454 if (!(qedi_dbg_log & QEDI_LOG_WARN))
55− return;
55+ goto ret;
5656
5757 if (likely(qedi) && likely(qedi->pdev))
5858 pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
@@ -60,6 +60,7 @@ qedi_dbg_warn(struct qedi_dbg_ctx *qedi, const char *func, u32 line, · 1 unmodified line
6060 else
6161 pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
6262
63+ret:
6364 va_end(va);
6465 }
6566
@@ -80,7 +81,7 @@ qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line, · 14 unmodified lines
8081 vaf.va = &va;
8182
8283 if (!(qedi_dbg_log & QEDI_LOG_NOTICE))
83− return;
84+ goto ret;
8485
8586 if (likely(qedi) && likely(qedi->pdev))
8687 pr_notice("[%s]:[%s:%d]:%d: %pV",
@@ -89,6 +90,7 @@ qedi_dbg_notice(struct qedi_dbg_ctx *qedi, const char *func, u32 line, · 2 unmodified lines
8990 else
9091 pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
9192
93+ret:
9294 va_end(va);
9395 }
9496
@@ -109,7 +111,7 @@ qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line, · 14 unmodified lines
109111 vaf.va = &va;
110112
111113 if (!(qedi_dbg_log & level))
112− return;
114+ goto ret;
113115
114116 if (likely(qedi) && likely(qedi->pdev))
115117 pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&qedi->pdev->dev),
@@ -117,6 +119,7 @@ qedi_dbg_info(struct qedi_dbg_ctx *qedi, const char *func, u32 line, · 1 unmodified line
117119 else
118120 pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf);
119121
122+ret:
120123 va_end(va);
121124 }
122125
drivers/scsi/qedi/qedi_iscsi.c+1−4
@@ -48,6 +48,7 @@ struct scsi_host_template qedi_host_template = { · 47 unmodified lines
4848 .name = "QLogic QEDI 25/40/100Gb iSCSI Initiator Driver",
4949 .proc_name = QEDI_MODULE_NAME,
5050 .queuecommand = iscsi_queuecommand,
51+ .eh_timed_out = iscsi_eh_cmd_timed_out,
5152 .eh_abort_handler = iscsi_eh_abort,
5253 .eh_device_reset_handler = iscsi_eh_device_reset,
5354 .eh_target_reset_handler = iscsi_eh_recover_target,
@@ -453,13 +454,9 @@ static int qedi_iscsi_update_conn(struct qedi_ctx *qedi, · 399 unmodified lines
453454 if (rval) {
454455 rval = -ENXIO;
455456 QEDI_ERR(&qedi->dbg_ctx, "Could not update connection\n");
456− goto update_conn_err;
457457 }
458458
459459 kfree(conn_info);
460− rval = 0;
461−
462−update_conn_err:
463460 return rval;
464461 }
465462
drivers/scsi/qla2xxx/qla_def.h+2−2
@@ -2248,7 +2248,7 @@ struct ct_fdmiv2_hba_attr { · 2247 unmodified lines
22482248 uint32_t num_ports;
22492249 uint8_t fabric_name[WWN_SIZE];
22502250 uint8_t bios_name[32];
2251− uint8_t vendor_indentifer[8];
2251+ uint8_t vendor_identifier[8];
22522252 } a;
22532253 };
22542254
@@ -2423,7 +2423,7 @@ struct ct_sns_req { · 168 unmodified lines
24232423 } rsnn_nn;
24242424
24252425 struct {
2426− uint8_t hba_indentifier[8];
2426+ uint8_t hba_identifier[8];
24272427 } ghat;
24282428
24292429 struct {
drivers/scsi/qla2xxx/qla_gs.c+3−3
@@ -1939,15 +1939,15 @@ qla2x00_fdmiv2_rhba(scsi_qla_host_t *vha) · 1938 unmodified lines
19391939 /* Vendor Identifier */
19401940 eiter = entries + size;
19411941 eiter->type = cpu_to_be16(FDMI_HBA_TYPE_VENDOR_IDENTIFIER);
1942− snprintf(eiter->a.vendor_indentifer, sizeof(eiter->a.vendor_indentifer),
1942+ snprintf(eiter->a.vendor_identifier, sizeof(eiter->a.vendor_identifier),
19431943 "%s", "QLGC");
1944− alen = strlen(eiter->a.vendor_indentifer);
1944+ alen = strlen(eiter->a.vendor_identifier);
19451945 alen += 4 - (alen & 3);
19461946 eiter->len = cpu_to_be16(4 + alen);
19471947 size += 4 + alen;
19481948
19491949 ql_dbg(ql_dbg_disc, vha, 0x20b1,
1950− "Vendor Identifier = %s.\n", eiter->a.vendor_indentifer);
1950+ "Vendor Identifier = %s.\n", eiter->a.vendor_identifier);
19511951
19521952 /* Update MS request size. */
19531953 qla2x00_update_ms_fdmi_iocb(vha, size + 16);
drivers/scsi/qla2xxx/qla_isr.c+5−5
@@ -2997,14 +2997,14 @@ struct qla_init_msix_entry { · 2996 unmodified lines
29972997 irq_handler_t handler;
29982998 };
29992999
3000−static struct qla_init_msix_entry msix_entries[] = {
3000+static const struct qla_init_msix_entry msix_entries[] = {
30013001 { "qla2xxx (default)", qla24xx_msix_default },
30023002 { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
30033003 { "qla2xxx (atio_q)", qla83xx_msix_atio_q },
30043004 { "qla2xxx (qpair_multiq)", qla2xxx_msix_rsp_q },
30053005 };
30063006
3007−static struct qla_init_msix_entry qla82xx_msix_entries[] = {
3007+static const struct qla_init_msix_entry qla82xx_msix_entries[] = {
30083008 { "qla2xxx (default)", qla82xx_msix_default },
30093009 { "qla2xxx (rsp_q)", qla82xx_msix_rsp_q },
30103010 };
@@ -3078,7 +3078,7 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp) · 67 unmodified lines
30783078 qentry->handle = rsp;
30793079 rsp->msix = qentry;
30803080 scnprintf(qentry->name, sizeof(qentry->name),
3081− msix_entries[i].name);
3081+ "%s", msix_entries[i].name);
30823082 if (IS_P3P_TYPE(ha))
30833083 ret = request_irq(qentry->vector,
30843084 qla82xx_msix_entries[i].handler,
@@ -3102,7 +3102,7 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp) · 17 unmodified lines
31023102 rsp->msix = qentry;
31033103 qentry->handle = rsp;
31043104 scnprintf(qentry->name, sizeof(qentry->name),
3105− msix_entries[QLA_ATIO_VECTOR].name);
3105+ "%s", msix_entries[QLA_ATIO_VECTOR].name);
31063106 qentry->in_use = 1;
31073107 ret = request_irq(qentry->vector,
31083108 msix_entries[QLA_ATIO_VECTOR].handler,
@@ -3271,7 +3271,7 @@ free_irqs: · 162 unmodified lines
32713271 int qla25xx_request_irq(struct qla_hw_data *ha, struct qla_qpair *qpair,
32723272 struct qla_msix_entry *msix, int vector_type)
32733273 {
3274− struct qla_init_msix_entry *intr = &msix_entries[vector_type];
3274+ const struct qla_init_msix_entry *intr = &msix_entries[vector_type];
32753275 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
32763276 int ret;
32773277
drivers/scsi/qla2xxx/qla_os.c+1−0
@@ -262,6 +262,7 @@ struct scsi_host_template qla2xxx_driver_template = { · 261 unmodified lines
262262 .name = QLA2XXX_DRIVER_NAME,
263263 .queuecommand = qla2xxx_queuecommand,
264264
265+ .eh_timed_out = fc_eh_timed_out,
265266 .eh_abort_handler = qla2xxx_eh_abort,
266267 .eh_device_reset_handler = qla2xxx_eh_device_reset,
267268 .eh_target_reset_handler = qla2xxx_eh_target_reset,
drivers/scsi/qla4xxx/ql4_def.h+0−3
@@ -408,9 +408,6 @@ struct qla4_8xxx_legacy_intr_set { · 407 unmodified lines
408408 };
409409
410410 /* MSI-X Support */
411−
412−#define QLA_MSIX_DEFAULT 0
413−#define QLA_MSIX_RSP_Q 1
414411 #define QLA_MSIX_ENTRIES 2
415412
416413 /*
drivers/scsi/qla4xxx/ql4_os.c+3−3
@@ -9539,15 +9539,15 @@ exit_host_reset: · 9538 unmodified lines
95399539 * driver calls the following device driver's callbacks
95409540 *
95419541 * - Fatal Errors - link_reset
9542− * - Non-Fatal Errors - driver's pci_error_detected() which
9542+ * - Non-Fatal Errors - driver's error_detected() which
95439543 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
95449544 *
95459545 * PCI AER driver calls
9546− * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
9546+ * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
95479547 * returns RECOVERED or NEED_RESET if fw_hung
95489548 * NEED_RESET - driver's slot_reset()
95499549 * DISCONNECT - device is dead & cannot recover
9550− * RECOVERED - driver's pci_resume()
9550+ * RECOVERED - driver's resume()
95519551 */
95529552 static pci_ers_result_t
95539553 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
drivers/scsi/scsi_debug.c+9−1
@@ -125,6 +125,7 @@ static const char *sdebug_version_date = "20160430"; · 124 unmodified lines
125125 #define DEF_OPTS 0
126126 #define DEF_OPT_BLKS 1024
127127 #define DEF_PHYSBLK_EXP 0
128+#define DEF_OPT_XFERLEN_EXP 0
128129 #define DEF_PTYPE TYPE_DISK
129130 #define DEF_REMOVABLE false
130131 #define DEF_SCSI_LEVEL 7 /* INQUIRY, byte2 [6->SPC-4; 7->SPC-5] */
@@ -590,6 +591,7 @@ static int sdebug_num_tgts = DEF_NUM_TGTS; /* targets per host */ · 459 unmodified lines
590591 static int sdebug_opt_blks = DEF_OPT_BLKS;
591592 static int sdebug_opts = DEF_OPTS;
592593 static int sdebug_physblk_exp = DEF_PHYSBLK_EXP;
594+static int sdebug_opt_xferlen_exp = DEF_OPT_XFERLEN_EXP;
593595 static int sdebug_ptype = DEF_PTYPE; /* SCSI peripheral device type */
594596 static int sdebug_scsi_level = DEF_SCSI_LEVEL;
595597 static int sdebug_sector_size = DEF_SECTOR_SIZE;
@@ -1205,7 +1207,11 @@ static int inquiry_vpd_b0(unsigned char *arr) · 609 unmodified lines
12051207 memcpy(arr, vpdb0_data, sizeof(vpdb0_data));
12061208
12071209 /* Optimal transfer length granularity */
1208− gran = 1 << sdebug_physblk_exp;
1210+ if (sdebug_opt_xferlen_exp != 0 &&
1211+ sdebug_physblk_exp < sdebug_opt_xferlen_exp)
1212+ gran = 1 << sdebug_opt_xferlen_exp;
1213+ else
1214+ gran = 1 << sdebug_physblk_exp;
12091215 put_unaligned_be16(gran, arr + 2);
12101216
12111217 /* Maximum Transfer Length */
@@ -4161,6 +4167,7 @@ module_param_named(num_tgts, sdebug_num_tgts, int, S_IRUGO | S_IWUSR); · 2949 unmodified lines
41614167 module_param_named(opt_blks, sdebug_opt_blks, int, S_IRUGO);
41624168 module_param_named(opts, sdebug_opts, int, S_IRUGO | S_IWUSR);
41634169 module_param_named(physblk_exp, sdebug_physblk_exp, int, S_IRUGO);
4170+module_param_named(opt_xferlen_exp, sdebug_opt_xferlen_exp, int, S_IRUGO);
41644171 module_param_named(ptype, sdebug_ptype, int, S_IRUGO | S_IWUSR);
41654172 module_param_named(removable, sdebug_removable, bool, S_IRUGO | S_IWUSR);
41664173 module_param_named(scsi_level, sdebug_scsi_level, int, S_IRUGO);
@@ -4212,6 +4219,7 @@ MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)"); · 45 unmodified lines
42124219 MODULE_PARM_DESC(opt_blks, "optimal transfer length in blocks (def=1024)");
42134220 MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
42144221 MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
4222+MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent (def=physblk_exp)");
42154223 MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
42164224 MODULE_PARM_DESC(removable, "claim to have removable media (def=0)");
42174225 MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=7[SPC-5])");
drivers/scsi/scsi_error.c+1−3
@@ -279,9 +279,7 @@ enum blk_eh_timer_return scsi_times_out(struct request *req) · 278 unmodified lines
279279 if (host->eh_deadline != -1 && !host->last_reset)
280280 host->last_reset = jiffies;
281281
282− if (host->transportt->eh_timed_out)
283− rtn = host->transportt->eh_timed_out(scmd);
284− else if (host->hostt->eh_timed_out)
282+ if (host->hostt->eh_timed_out)
285283 rtn = host->hostt->eh_timed_out(scmd);
286284
287285 if (rtn == BLK_EH_NOT_HANDLED) {
drivers/scsi/scsi_transport_fc.c+4−22
@@ -2055,7 +2055,7 @@ static int fc_vport_match(struct attribute_container *cont, · 2054 unmodified lines
20552055
20562056
20572057 /**
2058− * fc_timed_out - FC Transport I/O timeout intercept handler
2058+ * fc_eh_timed_out - FC Transport I/O timeout intercept handler
20592059 * @scmd: The SCSI command which timed out
20602060 *
20612061 * This routine protects against error handlers getting invoked while a
@@ -2076,8 +2076,8 @@ static int fc_vport_match(struct attribute_container *cont, · 14 unmodified lines
20762076 * Notes:
20772077 * This routine assumes no locks are held on entry.
20782078 */
2079−static enum blk_eh_timer_return
2080−fc_timed_out(struct scsi_cmnd *scmd)
2079+enum blk_eh_timer_return
2080+fc_eh_timed_out(struct scsi_cmnd *scmd)
20812081 {
20822082 struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device));
20832083
@@ -2086,6 +2086,7 @@ fc_timed_out(struct scsi_cmnd *scmd) · 2 unmodified lines
20862086
20872087 return BLK_EH_NOT_HANDLED;
20882088 }
2089+EXPORT_SYMBOL(fc_eh_timed_out);
20892090
20902091 /*
20912092 * Called by fc_user_scan to locate an rport on the shost that
@@ -2159,19 +2160,6 @@ fc_user_scan(struct Scsi_Host *shost, uint channel, uint id, u64 lun) · 67 unmodified lines
21592160 return 0;
21602161 }
21612162
2162−static int fc_tsk_mgmt_response(struct Scsi_Host *shost, u64 nexus, u64 tm_id,
2163− int result)
2164−{
2165− struct fc_internal *i = to_fc_internal(shost->transportt);
2166− return i->f->tsk_mgmt_response(shost, nexus, tm_id, result);
2167−}
2168−
2169−static int fc_it_nexus_response(struct Scsi_Host *shost, u64 nexus, int result)
2170−{
2171− struct fc_internal *i = to_fc_internal(shost->transportt);
2172− return i->f->it_nexus_response(shost, nexus, result);
2173−}
2174−
21752163 struct scsi_transport_template *
21762164 fc_attach_transport(struct fc_function_template *ft)
21772165 {
@@ -2211,14 +2199,8 @@ fc_attach_transport(struct fc_function_template *ft) · 33 unmodified lines
22112199 /* Transport uses the shost workq for scsi scanning */
22122200 i->t.create_work_queue = 1;
22132201
2214− i->t.eh_timed_out = fc_timed_out;
2215−
22162202 i->t.user_scan = fc_user_scan;
22172203
2218− /* target-mode drivers' functions */
2219− i->t.tsk_mgmt_response = fc_tsk_mgmt_response;
2220− i->t.it_nexus_response = fc_it_nexus_response;
2221−
22222204 /*
22232205 * Setup SCSI Target Attributes.
22242206 */
drivers/scsi/scsi_transport_srp.c+2−19
@@ -591,7 +591,7 @@ EXPORT_SYMBOL(srp_reconnect_rport); · 590 unmodified lines
591591 * Note: This function is called from soft-IRQ context and with the request
592592 * queue lock held.
593593 */
594−static enum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd)
594+enum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd)
595595 {
596596 struct scsi_device *sdev = scmd->device;
597597 struct Scsi_Host *shost = sdev->host;
@@ -603,6 +603,7 @@ static enum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd) · 5 unmodified lines
603603 i->f->reset_timer_if_blocked && scsi_device_blocked(sdev) ?
604604 BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
605605 }
606+EXPORT_SYMBOL(srp_timed_out);
606607
607608 static void srp_rport_release(struct device *dev)
608609 {
@@ -793,19 +794,6 @@ void srp_stop_rport_timers(struct srp_rport *rport) · 184 unmodified lines
793794 }
794795 EXPORT_SYMBOL_GPL(srp_stop_rport_timers);
795796
796−static int srp_tsk_mgmt_response(struct Scsi_Host *shost, u64 nexus, u64 tm_id,
797− int result)
798−{
799− struct srp_internal *i = to_srp_internal(shost->transportt);
800− return i->f->tsk_mgmt_response(shost, nexus, tm_id, result);
801−}
802−
803−static int srp_it_nexus_response(struct Scsi_Host *shost, u64 nexus, int result)
804−{
805− struct srp_internal *i = to_srp_internal(shost->transportt);
806− return i->f->it_nexus_response(shost, nexus, result);
807−}
808−
809797 /**
810798 * srp_attach_transport - instantiate SRP transport template
811799 * @ft: SRP transport class function template
@@ -820,11 +808,6 @@ srp_attach_transport(struct srp_function_template *ft) · 8 unmodified lines
820808 if (!i)
821809 return NULL;
822810
823− i->t.eh_timed_out = srp_timed_out;
824−
825− i->t.tsk_mgmt_response = srp_tsk_mgmt_response;
826− i->t.it_nexus_response = srp_it_nexus_response;
827−
828811 i->t.host_size = sizeof(struct srp_host_attrs);
829812 i->t.host_attrs.ac.attrs = &i->host_attrs[0];
830813 i->t.host_attrs.ac.class = &srp_host_class.class;
drivers/scsi/sd.c+2−2
@@ -703,7 +703,7 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode) · 702 unmodified lines
703703
704704 /**
705705 * sd_setup_discard_cmnd - unmap blocks on thinly provisioned device
706− * @sdp: scsi device to operate one
706+ * @sdp: scsi device to operate on
707707 * @rq: Request to prepare
708708 *
709709 * Will issue either UNMAP or WRITE SAME(16) depending on preference
@@ -3226,7 +3226,7 @@ static int sd_probe(struct device *dev) · 2516 unmodified lines
32263226 * sd_remove - called whenever a scsi disk (previously recognized by
32273227 * sd_probe) is detached from the system. It is called (potentially
32283228 * multiple times) during sd module unload.
3229− * @sdp: pointer to mid level scsi device object
3229+ * @dev: pointer to device object
32303230 *
32313231 * Note: this function is invoked from the scsi mid-level.
32323232 * This function potentially frees up a device name (e.g. /dev/sdc)
drivers/scsi/snic/snic.h+0−1
@@ -299,7 +299,6 @@ struct snic { · 298 unmodified lines
299299
300300 /* pci related */
301301 struct pci_dev *pdev;
302− struct msix_entry msix_entry[SNIC_MSIX_INTR_MAX];
303302 struct snic_msix_entry msix[SNIC_MSIX_INTR_MAX];
304303
305304 /* io related info */
drivers/scsi/snic/snic_isr.c+19−29
@@ -93,7 +93,7 @@ snic_free_intr(struct snic *snic) · 92 unmodified lines
9393 /* ONLY interrupt mode MSIX is supported */
9494 for (i = 0; i < ARRAY_SIZE(snic->msix); i++) {
9595 if (snic->msix[i].requested) {
96− free_irq(snic->msix_entry[i].vector,
96+ free_irq(pci_irq_vector(snic->pdev, i),
9797 snic->msix[i].devid);
9898 }
9999 }
@@ -134,7 +134,7 @@ snic_request_intr(struct snic *snic) · 34 unmodified lines
134134 snic->msix[SNIC_MSIX_ERR_NOTIFY].devid = snic;
135135
136136 for (i = 0; i < ARRAY_SIZE(snic->msix); i++) {
137− ret = request_irq(snic->msix_entry[i].vector,
137+ ret = request_irq(pci_irq_vector(snic->pdev, i),
138138 snic->msix[i].isr,
139139 0,
140140 snic->msix[i].devname,
@@ -158,47 +158,37 @@ snic_set_intr_mode(struct snic *snic) · 17 unmodified lines
158158 {
159159 unsigned int n = ARRAY_SIZE(snic->wq);
160160 unsigned int m = SNIC_CQ_IO_CMPL_MAX;
161− unsigned int i;
161+ unsigned int vecs = n + m + 1;
162162
163163 /*
164164 * We need n WQs, m CQs, and n+m+1 INTRs
165165 * (last INTR is used for WQ/CQ errors and notification area
166166 */
167−
168167 BUILD_BUG_ON((ARRAY_SIZE(snic->wq) + SNIC_CQ_IO_CMPL_MAX) >
169168 ARRAY_SIZE(snic->intr));
170− SNIC_BUG_ON(ARRAY_SIZE(snic->msix_entry) < (n + m + 1));
171−
172− for (i = 0; i < (n + m + 1); i++)
173− snic->msix_entry[i].entry = i;
174−
175− if (snic->wq_count >= n && snic->cq_count >= (n + m)) {
176− if (!pci_enable_msix(snic->pdev,
177− snic->msix_entry,
178− (n + m + 1))) {
179− snic->wq_count = n;
180− snic->cq_count = n + m;
181− snic->intr_count = n + m + 1;
182− snic->err_intr_offset = SNIC_MSIX_ERR_NOTIFY;
183−
184− SNIC_ISR_DBG(snic->shost,
185− "Using MSI-X Interrupts\n");
186− svnic_dev_set_intr_mode(snic->vdev,
187− VNIC_DEV_INTR_MODE_MSIX);
188−
189− return 0;
190− }
191− }
192169
193− svnic_dev_set_intr_mode(snic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
170+ if (snic->wq_count < n || snic->cq_count < n + m)
171+ goto fail;
194172
173+ if (pci_alloc_irq_vectors(snic->pdev, vecs, vecs, PCI_IRQ_MSIX) < 0)
174+ goto fail;
175+
176+ snic->wq_count = n;
177+ snic->cq_count = n + m;
178+ snic->intr_count = vecs;
179+ snic->err_intr_offset = SNIC_MSIX_ERR_NOTIFY;
180+
181+ SNIC_ISR_DBG(snic->shost, "Using MSI-X Interrupts\n");
182+ svnic_dev_set_intr_mode(snic->vdev, VNIC_DEV_INTR_MODE_MSIX);
183+ return 0;
184+fail:
185+ svnic_dev_set_intr_mode(snic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
195186 return -EINVAL;
196187 } /* end of snic_set_intr_mode */
197188
198189 void
199190 snic_clear_intr_mode(struct snic *snic)
200191 {
201− pci_disable_msix(snic->pdev);
202−
192+ pci_free_irq_vectors(snic->pdev);
203193 svnic_dev_set_intr_mode(snic->vdev, VNIC_DEV_INTR_MODE_INTX);
204194 }
drivers/scsi/storvsc_drv.c+140−20
@@ -136,6 +136,8 @@ struct hv_fc_wwn_packet { · 135 unmodified lines
136136 #define SRB_FLAGS_PORT_DRIVER_RESERVED 0x0F000000
137137 #define SRB_FLAGS_CLASS_DRIVER_RESERVED 0xF0000000
138138
139+#define SP_UNTAGGED ((unsigned char) ~0)
140+#define SRB_SIMPLE_TAG_REQUEST 0x20
139141
140142 /*
141143 * Platform neutral description of a scsi request -
@@ -375,6 +377,7 @@ enum storvsc_request_type { · 233 unmodified lines
375377 #define SRB_STATUS_SUCCESS 0x01
376378 #define SRB_STATUS_ABORTED 0x02
377379 #define SRB_STATUS_ERROR 0x04
380+#define SRB_STATUS_DATA_OVERRUN 0x12
378381
379382 #define SRB_STATUS(status) \
380383 (status & ~(SRB_STATUS_AUTOSENSE_VALID | SRB_STATUS_QUEUE_FROZEN))
@@ -458,6 +461,15 @@ struct storvsc_device { · 77 unmodified lines
458461 * Max I/O, the device can support.
459462 */
460463 u32 max_transfer_bytes;
464+ /*
465+ * Number of sub-channels we will open.
466+ */
467+ u16 num_sc;
468+ struct vmbus_channel **stor_chns;
469+ /*
470+ * Mask of CPUs bound to subchannels.
471+ */
472+ struct cpumask alloced_cpus;
461473 /* Used for vsc/vsp channel reset process */
462474 struct storvsc_cmd_request init_request;
463475 struct storvsc_cmd_request reset_request;
@@ -635,6 +647,11 @@ static void handle_sc_creation(struct vmbus_channel *new_sc) · 171 unmodified lines
635647 (void *)&props,
636648 sizeof(struct vmstorage_channel_properties),
637649 storvsc_on_channel_callback, new_sc);
650+
651+ if (new_sc->state == CHANNEL_OPENED_STATE) {
652+ stor_device->stor_chns[new_sc->target_cpu] = new_sc;
653+ cpumask_set_cpu(new_sc->target_cpu, &stor_device->alloced_cpus);
654+ }
638655 }
639656
640657 static void handle_multichannel_storage(struct hv_device *device, int max_chns)
@@ -651,6 +668,7 @@ static void handle_multichannel_storage(struct hv_device *device, int max_chns) · 10 unmodified lines
651668 if (!stor_device)
652669 return;
653670
671+ stor_device->num_sc = num_sc;
654672 request = &stor_device->init_request;
655673 vstor_packet = &request->vstor_packet;
656674
@@ -838,6 +856,25 @@ static int storvsc_channel_init(struct hv_device *device, bool is_fc) · 181 unmodified lines
838856 * support multi-channel.
839857 */
840858 max_chns = vstor_packet->storage_channel_properties.max_channel_cnt;
859+
860+ /*
861+ * Allocate state to manage the sub-channels.
862+ * We allocate an array based on the numbers of possible CPUs
863+ * (Hyper-V does not support cpu online/offline).
864+ * This Array will be sparseley populated with unique
865+ * channels - primary + sub-channels.
866+ * We will however populate all the slots to evenly distribute
867+ * the load.
868+ */
869+ stor_device->stor_chns = kzalloc(sizeof(void *) * num_possible_cpus(),
870+ GFP_KERNEL);
871+ if (stor_device->stor_chns == NULL)
872+ return -ENOMEM;
873+
874+ stor_device->stor_chns[device->channel->target_cpu] = device->channel;
875+ cpumask_set_cpu(device->channel->target_cpu,
876+ &stor_device->alloced_cpus);
877+
841878 if (vmstor_proto_version >= VMSTOR_PROTO_VERSION_WIN8) {
842879 if (vstor_packet->storage_channel_properties.flags &
843880 STORAGE_CHANNEL_SUPPORTS_MULTI_CHANNEL)
@@ -888,6 +925,13 @@ static void storvsc_handle_error(struct vmscsi_request *vm_srb, · 44 unmodified lines
888925
889926 switch (SRB_STATUS(vm_srb->srb_status)) {
890927 case SRB_STATUS_ERROR:
928+ /*
929+ * Let upper layer deal with error when
930+ * sense message is present.
931+ */
932+
933+ if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID)
934+ break;
891935 /*
892936 * If there is an error; offline the device since all
893937 * error recovery strategies would have already been
@@ -953,6 +997,7 @@ static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request, · 59 unmodified lines
953997 struct scsi_cmnd *scmnd = cmd_request->cmd;
954998 struct scsi_sense_hdr sense_hdr;
955999 struct vmscsi_request *vm_srb;
1000+ u32 data_transfer_length;
9561001 struct Scsi_Host *host;
9571002 u32 payload_sz = cmd_request->payload_sz;
9581003 void *payload = cmd_request->payload;
@@ -960,6 +1005,7 @@ static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request, · 1 unmodified line
9601005 host = stor_dev->host;
9611006
9621007 vm_srb = &cmd_request->vstor_packet.vm_srb;
1008+ data_transfer_length = vm_srb->data_transfer_length;
9631009
9641010 scmnd->result = vm_srb->scsi_status;
9651011
@@ -973,13 +1019,20 @@ static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request, · 7 unmodified lines
9731019 &sense_hdr);
9741020 }
9751021
976− if (vm_srb->srb_status != SRB_STATUS_SUCCESS)
1022+ if (vm_srb->srb_status != SRB_STATUS_SUCCESS) {
9771023 storvsc_handle_error(vm_srb, scmnd, host, sense_hdr.asc,
9781024 sense_hdr.ascq);
1025+ /*
1026+ * The Windows driver set data_transfer_length on
1027+ * SRB_STATUS_DATA_OVERRUN. On other errors, this value
1028+ * is untouched. In these cases we set it to 0.
1029+ */
1030+ if (vm_srb->srb_status != SRB_STATUS_DATA_OVERRUN)
1031+ data_transfer_length = 0;
1032+ }
9791033
9801034 scsi_set_resid(scmnd,
981− cmd_request->payload->range.len -
982− vm_srb->data_transfer_length);
1035+ cmd_request->payload->range.len - data_transfer_length);
9831036
9841037 scmnd->scsi_done(scmnd);
9851038
@@ -1198,17 +1251,64 @@ static int storvsc_dev_remove(struct hv_device *device) · 212 unmodified lines
11981251 /* Close the channel */
11991252 vmbus_close(device->channel);
12001253
1254+ kfree(stor_device->stor_chns);
12011255 kfree(stor_device);
12021256 return 0;
12031257 }
12041258
1259+static struct vmbus_channel *get_og_chn(struct storvsc_device *stor_device,
1260+ u16 q_num)
1261+{
1262+ u16 slot = 0;
1263+ u16 hash_qnum;
1264+ struct cpumask alloced_mask;
1265+ int num_channels, tgt_cpu;
1266+
1267+ if (stor_device->num_sc == 0)
1268+ return stor_device->device->channel;
1269+
1270+ /*
1271+ * Our channel array is sparsley populated and we
1272+ * initiated I/O on a processor/hw-q that does not
1273+ * currently have a designated channel. Fix this.
1274+ * The strategy is simple:
1275+ * I. Ensure NUMA locality
1276+ * II. Distribute evenly (best effort)
1277+ * III. Mapping is persistent.
1278+ */
1279+
1280+ cpumask_and(&alloced_mask, &stor_device->alloced_cpus,
1281+ cpumask_of_node(cpu_to_node(q_num)));
1282+
1283+ num_channels = cpumask_weight(&alloced_mask);
1284+ if (num_channels == 0)
1285+ return stor_device->device->channel;
1286+
1287+ hash_qnum = q_num;
1288+ while (hash_qnum >= num_channels)
1289+ hash_qnum -= num_channels;
1290+
1291+ for_each_cpu(tgt_cpu, &alloced_mask) {
1292+ if (slot == hash_qnum)
1293+ break;
1294+ slot++;
1295+ }
1296+
1297+ stor_device->stor_chns[q_num] = stor_device->stor_chns[tgt_cpu];
1298+
1299+ return stor_device->stor_chns[q_num];
1300+}
1301+
1302+
12051303 static int storvsc_do_io(struct hv_device *device,
1206− struct storvsc_cmd_request *request)
1304+ struct storvsc_cmd_request *request, u16 q_num)
12071305 {
12081306 struct storvsc_device *stor_device;
12091307 struct vstor_packet *vstor_packet;
12101308 struct vmbus_channel *outgoing_channel;
12111309 int ret = 0;
1310+ struct cpumask alloced_mask;
1311+ int tgt_cpu;
12121312
12131313 vstor_packet = &request->vstor_packet;
12141314 stor_device = get_out_stor_device(device);
@@ -1222,7 +1322,26 @@ static int storvsc_do_io(struct hv_device *device, · 7 unmodified lines
12221322 * Select an an appropriate channel to send the request out.
12231323 */
12241324
1225− outgoing_channel = vmbus_get_outgoing_channel(device->channel);
1325+ if (stor_device->stor_chns[q_num] != NULL) {
1326+ outgoing_channel = stor_device->stor_chns[q_num];
1327+ if (outgoing_channel->target_cpu == smp_processor_id()) {
1328+ /*
1329+ * Ideally, we want to pick a different channel if
1330+ * available on the same NUMA node.
1331+ */
1332+ cpumask_and(&alloced_mask, &stor_device->alloced_cpus,
1333+ cpumask_of_node(cpu_to_node(q_num)));
1334+ for_each_cpu(tgt_cpu, &alloced_mask) {
1335+ if (tgt_cpu != outgoing_channel->target_cpu) {
1336+ outgoing_channel =
1337+ stor_device->stor_chns[tgt_cpu];
1338+ break;
1339+ }
1340+ }
1341+ }
1342+ } else {
1343+ outgoing_channel = get_og_chn(stor_device, q_num);
1344+ }
12261345
12271346
12281347 vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
@@ -1267,8 +1386,6 @@ static int storvsc_do_io(struct hv_device *device, · 38 unmodified lines
12671386 static int storvsc_device_configure(struct scsi_device *sdevice)
12681387 {
12691388
1270− blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
1271−
12721389 blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY);
12731390
12741391 blk_queue_rq_timeout(sdevice->request_queue, (storvsc_timeout * HZ));
@@ -1451,6 +1568,13 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd) · 176 unmodified lines
14511568 vm_srb->win8_extension.srb_flags |=
14521569 SRB_FLAGS_DISABLE_SYNCH_TRANSFER;
14531570
1571+ if (scmnd->device->tagged_supported) {
1572+ vm_srb->win8_extension.srb_flags |=
1573+ (SRB_FLAGS_QUEUE_ACTION_ENABLE | SRB_FLAGS_NO_QUEUE_FREEZE);
1574+ vm_srb->win8_extension.queue_tag = SP_UNTAGGED;
1575+ vm_srb->win8_extension.queue_action = SRB_SIMPLE_TAG_REQUEST;
1576+ }
1577+
14541578 /* Build the SRB */
14551579 switch (scmnd->sc_data_direction) {
14561580 case DMA_TO_DEVICE:
@@ -1511,20 +1635,14 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd) · 54 unmodified lines
15111635 page_to_pfn(sg_page((cur_sgl)));
15121636 cur_sgl = sg_next(cur_sgl);
15131637 }
1514−
1515− } else if (scsi_sglist(scmnd)) {
1516− payload->range.len = length;
1517− payload->range.offset =
1518− virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1);
1519− payload->range.pfn_array[0] =
1520− virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT;
15211638 }
15221639
15231640 cmd_request->payload = payload;
15241641 cmd_request->payload_sz = payload_sz;
15251642
15261643 /* Invokes the vsc to start an IO */
1527− ret = storvsc_do_io(dev, cmd_request);
1644+ ret = storvsc_do_io(dev, cmd_request, get_cpu());
1645+ put_cpu();
15281646
15291647 if (ret == -EAGAIN) {
15301648 /* no more space */
@@ -1550,6 +1668,7 @@ static struct scsi_host_template scsi_driver = { · 19 unmodified lines
15501668 /* Make sure we dont get a sg segment crosses a page boundary */
15511669 .dma_boundary = PAGE_SIZE-1,
15521670 .no_write_same = 1,
1671+ .track_queue_depth = 1,
15531672 };
15541673
15551674 enum {
@@ -1680,6 +1799,11 @@ static int storvsc_probe(struct hv_device *device, · 124 unmodified lines
16801799 * from the host.
16811800 */
16821801 host->sg_tablesize = (stor_device->max_transfer_bytes >> PAGE_SHIFT);
1802+ /*
1803+ * Set the number of HW queues we are supporting.
1804+ */
1805+ if (stor_device->num_sc != 0)
1806+ host->nr_hw_queues = stor_device->num_sc + 1;
16831807
16841808 /* Register the HBA and start the scsi bus scan */
16851809 ret = scsi_add_host(host, &device->device);
@@ -1716,6 +1840,7 @@ err_out2: · 30 unmodified lines
17161840 goto err_out0;
17171841
17181842 err_out1:
1843+ kfree(stor_device->stor_chns);
17191844 kfree(stor_device);
17201845
17211846 err_out0:
@@ -1774,11 +1899,6 @@ static int __init storvsc_drv_init(void) · 52 unmodified lines
17741899 fc_transport_template = fc_attach_transport(&fc_transport_functions);
17751900 if (!fc_transport_template)
17761901 return -ENODEV;
1777−
1778− /*
1779− * Install Hyper-V specific timeout handler.
1780− */
1781− fc_transport_template->eh_timed_out = storvsc_eh_timed_out;
17821902 #endif
17831903
17841904 ret = vmbus_driver_register(&storvsc_drv);
drivers/scsi/sun3_scsi.c+79−4
@@ -34,7 +34,6 @@ · 33 unmodified lines
3434 #include <asm/dvma.h>
3535
3636 #include <scsi/scsi_host.h>
37−#include "sun3_scsi.h"
3837
3938 /* minimum number of bytes to do dma on */
4039 #define DMA_MIN_SIZE 129
@@ -56,11 +55,87 @@ · 15 unmodified lines
5655 #define NCR5380_dma_send_setup sun3scsi_dma_count
5756 #define NCR5380_dma_residual sun3scsi_dma_residual
5857
59−#define NCR5380_acquire_dma_irq(instance) (1)
60−#define NCR5380_release_dma_irq(instance)
61−
6258 #include "NCR5380.h"
6359
60+/* dma regs start at regbase + 8, directly after the NCR regs */
61+struct sun3_dma_regs {
62+ unsigned short dma_addr_hi; /* vme only */
63+ unsigned short dma_addr_lo; /* vme only */
64+ unsigned short dma_count_hi; /* vme only */
65+ unsigned short dma_count_lo; /* vme only */
66+ unsigned short udc_data; /* udc dma data reg (obio only) */
67+ unsigned short udc_addr; /* uda dma addr reg (obio only) */
68+ unsigned short fifo_data; /* fifo data reg,
69+ * holds extra byte on odd dma reads
70+ */
71+ unsigned short fifo_count;
72+ unsigned short csr; /* control/status reg */
73+ unsigned short bpack_hi; /* vme only */
74+ unsigned short bpack_lo; /* vme only */
75+ unsigned short ivect; /* vme only */
76+ unsigned short fifo_count_hi; /* vme only */
77+};
78+
79+/* ucd chip specific regs - live in dvma space */
80+struct sun3_udc_regs {
81+ unsigned short rsel; /* select regs to load */
82+ unsigned short addr_hi; /* high word of addr */
83+ unsigned short addr_lo; /* low word */
84+ unsigned short count; /* words to be xfer'd */
85+ unsigned short mode_hi; /* high word of channel mode */
86+ unsigned short mode_lo; /* low word of channel mode */
87+};
88+
89+/* addresses of the udc registers */
90+#define UDC_MODE 0x38
91+#define UDC_CSR 0x2e /* command/status */
92+#define UDC_CHN_HI 0x26 /* chain high word */
93+#define UDC_CHN_LO 0x22 /* chain lo word */
94+#define UDC_CURA_HI 0x1a /* cur reg A high */
95+#define UDC_CURA_LO 0x0a /* cur reg A low */
96+#define UDC_CURB_HI 0x12 /* cur reg B high */
97+#define UDC_CURB_LO 0x02 /* cur reg B low */
98+#define UDC_MODE_HI 0x56 /* mode reg high */
99+#define UDC_MODE_LO 0x52 /* mode reg low */
100+#define UDC_COUNT 0x32 /* words to xfer */
101+
102+/* some udc commands */
103+#define UDC_RESET 0
104+#define UDC_CHN_START 0xa0 /* start chain */
105+#define UDC_INT_ENABLE 0x32 /* channel 1 int on */
106+
107+/* udc mode words */
108+#define UDC_MODE_HIWORD 0x40
109+#define UDC_MODE_LSEND 0xc2
110+#define UDC_MODE_LRECV 0xd2
111+
112+/* udc reg selections */
113+#define UDC_RSEL_SEND 0x282
114+#define UDC_RSEL_RECV 0x182
115+
116+/* bits in csr reg */
117+#define CSR_DMA_ACTIVE 0x8000
118+#define CSR_DMA_CONFLICT 0x4000
119+#define CSR_DMA_BUSERR 0x2000
120+
121+#define CSR_FIFO_EMPTY 0x400 /* fifo flushed? */
122+#define CSR_SDB_INT 0x200 /* sbc interrupt pending */
123+#define CSR_DMA_INT 0x100 /* dma interrupt pending */
124+
125+#define CSR_LEFT 0xc0
126+#define CSR_LEFT_3 0xc0
127+#define CSR_LEFT_2 0x80
128+#define CSR_LEFT_1 0x40
129+#define CSR_PACK_ENABLE 0x20
130+
131+#define CSR_DMA_ENABLE 0x10
132+
133+#define CSR_SEND 0x8 /* 1 = send 0 = recv */
134+#define CSR_FIFO 0x2 /* reset fifo */
135+#define CSR_INTR 0x4 /* interrupt enable */
136+#define CSR_SCSI 0x1
137+
138+#define VME_DATA24 0x3d00
64139
65140 extern int sun3_map_test(unsigned long, char *);
66141
drivers/scsi/sun3_scsi.h+0−102
@@ -1,102 +0,0 @@
1−/*
2− * Sun3 SCSI stuff by Erik Verbruggen (erik@bigmama.xtdnet.nl)
3− *
4− * Sun3 DMA additions by Sam Creasey (sammy@sammy.net)
5− *
6− * Adapted from mac_scsinew.h:
7− */
8−/*
9− * Cumana Generic NCR5380 driver defines
10− *
11− * Copyright 1993, Drew Eckhardt
12− * Visionary Computing
13− * (Unix and Linux consulting and custom programming)
14− * drew@colorado.edu
15− * +1 (303) 440-4894
16− */
17−
18−#ifndef SUN3_SCSI_H
19−#define SUN3_SCSI_H
20−
21−/* additional registers - mainly DMA control regs */
22−/* these start at regbase + 8 -- directly after the NCR regs */
23−struct sun3_dma_regs {
24− unsigned short dma_addr_hi; /* vme only */
25− unsigned short dma_addr_lo; /* vme only */
26− unsigned short dma_count_hi; /* vme only */
27− unsigned short dma_count_lo; /* vme only */
28− unsigned short udc_data; /* udc dma data reg (obio only) */
29− unsigned short udc_addr; /* uda dma addr reg (obio only) */
30− unsigned short fifo_data; /* fifo data reg, holds extra byte on
31− odd dma reads */
32− unsigned short fifo_count;
33− unsigned short csr; /* control/status reg */
34− unsigned short bpack_hi; /* vme only */
35− unsigned short bpack_lo; /* vme only */
36− unsigned short ivect; /* vme only */
37− unsigned short fifo_count_hi; /* vme only */
38−};
39−
40−/* ucd chip specific regs - live in dvma space */
41−struct sun3_udc_regs {
42− unsigned short rsel; /* select regs to load */
43− unsigned short addr_hi; /* high word of addr */
44− unsigned short addr_lo; /* low word */
45− unsigned short count; /* words to be xfer'd */
46− unsigned short mode_hi; /* high word of channel mode */
47− unsigned short mode_lo; /* low word of channel mode */
48−};
49−
50−/* addresses of the udc registers */
51−#define UDC_MODE 0x38
52−#define UDC_CSR 0x2e /* command/status */
53−#define UDC_CHN_HI 0x26 /* chain high word */
54−#define UDC_CHN_LO 0x22 /* chain lo word */
55−#define UDC_CURA_HI 0x1a /* cur reg A high */
56−#define UDC_CURA_LO 0x0a /* cur reg A low */
57−#define UDC_CURB_HI 0x12 /* cur reg B high */
58−#define UDC_CURB_LO 0x02 /* cur reg B low */
59−#define UDC_MODE_HI 0x56 /* mode reg high */
60−#define UDC_MODE_LO 0x52 /* mode reg low */
61−#define UDC_COUNT 0x32 /* words to xfer */
62−
63−/* some udc commands */
64−#define UDC_RESET 0
65−#define UDC_CHN_START 0xa0 /* start chain */
66−#define UDC_INT_ENABLE 0x32 /* channel 1 int on */
67−
68−/* udc mode words */
69−#define UDC_MODE_HIWORD 0x40
70−#define UDC_MODE_LSEND 0xc2
71−#define UDC_MODE_LRECV 0xd2
72−
73−/* udc reg selections */
74−#define UDC_RSEL_SEND 0x282
75−#define UDC_RSEL_RECV 0x182
76−
77−/* bits in csr reg */
78−#define CSR_DMA_ACTIVE 0x8000
79−#define CSR_DMA_CONFLICT 0x4000
80−#define CSR_DMA_BUSERR 0x2000
81−
82−#define CSR_FIFO_EMPTY 0x400 /* fifo flushed? */
83−#define CSR_SDB_INT 0x200 /* sbc interrupt pending */
84−#define CSR_DMA_INT 0x100 /* dma interrupt pending */
85−
86−#define CSR_LEFT 0xc0
87−#define CSR_LEFT_3 0xc0
88−#define CSR_LEFT_2 0x80
89−#define CSR_LEFT_1 0x40
90−#define CSR_PACK_ENABLE 0x20
91−
92−#define CSR_DMA_ENABLE 0x10
93−
94−#define CSR_SEND 0x8 /* 1 = send 0 = recv */
95−#define CSR_FIFO 0x2 /* reset fifo */
96−#define CSR_INTR 0x4 /* interrupt enable */
97−#define CSR_SCSI 0x1
98−
99−#define VME_DATA24 0x3d00
100−
101−#endif /* SUN3_SCSI_H */
102−
drivers/scsi/ufs/ufs-qcom.c+43−6
@@ -1497,17 +1497,21 @@ static void ufs_qcom_print_hw_debug_reg_all(struct ufs_hba *hba, · 1496 unmodified lines
14971497
14981498 static void ufs_qcom_enable_test_bus(struct ufs_qcom_host *host)
14991499 {
1500− if (host->dbg_print_en & UFS_QCOM_DBG_PRINT_TEST_BUS_EN)
1500+ if (host->dbg_print_en & UFS_QCOM_DBG_PRINT_TEST_BUS_EN) {
1501+ ufshcd_rmwl(host->hba, UFS_REG_TEST_BUS_EN,
1502+ UFS_REG_TEST_BUS_EN, REG_UFS_CFG1);
15011503 ufshcd_rmwl(host->hba, TEST_BUS_EN, TEST_BUS_EN, REG_UFS_CFG1);
1502− else
1504+ } else {
1505+ ufshcd_rmwl(host->hba, UFS_REG_TEST_BUS_EN, 0, REG_UFS_CFG1);
15031506 ufshcd_rmwl(host->hba, TEST_BUS_EN, 0, REG_UFS_CFG1);
1507+ }
15041508 }
15051509
15061510 static void ufs_qcom_get_default_testbus_cfg(struct ufs_qcom_host *host)
15071511 {
15081512 /* provide a legal default configuration */
1509− host->testbus.select_major = TSTBUS_UAWM;
1510− host->testbus.select_minor = 1;
1513+ host->testbus.select_major = TSTBUS_UNIPRO;
1514+ host->testbus.select_minor = 37;
15111515 }
15121516
15131517 static bool ufs_qcom_testbus_cfg_is_ok(struct ufs_qcom_host *host)
@@ -1524,7 +1528,7 @@ static bool ufs_qcom_testbus_cfg_is_ok(struct ufs_qcom_host *host) · 10 unmodified lines
15241528 * mappings of select_minor, since there is no harm in
15251529 * configuring a non-existent select_minor
15261530 */
1527− if (host->testbus.select_minor > 0x1F) {
1531+ if (host->testbus.select_minor > 0xFF) {
15281532 dev_err(host->hba->dev,
15291533 "%s: 0x%05X is not a legal testbus option\n",
15301534 __func__, host->testbus.select_minor);
@@ -1593,7 +1597,8 @@ int ufs_qcom_testbus_config(struct ufs_qcom_host *host) · 62 unmodified lines
15931597 break;
15941598 case TSTBUS_UNIPRO:
15951599 reg = UFS_UNIPRO_CFG;
1596− offset = 1;
1600+ offset = 20;
1601+ mask = 0xFFF;
15971602 break;
15981603 /*
15991604 * No need for a default case, since
@@ -1612,6 +1617,11 @@ int ufs_qcom_testbus_config(struct ufs_qcom_host *host) · 12 unmodified lines
16121617 (u32)host->testbus.select_minor << offset,
16131618 reg);
16141619 ufs_qcom_enable_test_bus(host);
1620+ /*
1621+ * Make sure the test bus configuration is
1622+ * committed before returning.
1623+ */
1624+ mb();
16151625 ufshcd_release(host->hba);
16161626 pm_runtime_put_sync(host->hba->dev);
16171627
@@ -1623,13 +1633,39 @@ static void ufs_qcom_testbus_read(struct ufs_hba *hba) · 5 unmodified lines
16231633 ufs_qcom_dump_regs(hba, UFS_TEST_BUS, 1, "UFS_TEST_BUS ");
16241634 }
16251635
1636+static void ufs_qcom_print_unipro_testbus(struct ufs_hba *hba)
1637+{
1638+ struct ufs_qcom_host *host = ufshcd_get_variant(hba);
1639+ u32 *testbus = NULL;
1640+ int i, nminor = 256, testbus_len = nminor * sizeof(u32);
1641+
1642+ testbus = kmalloc(testbus_len, GFP_KERNEL);
1643+ if (!testbus)
1644+ return;
1645+
1646+ host->testbus.select_major = TSTBUS_UNIPRO;
1647+ for (i = 0; i < nminor; i++) {
1648+ host->testbus.select_minor = i;
1649+ ufs_qcom_testbus_config(host);
1650+ testbus[i] = ufshcd_readl(hba, UFS_TEST_BUS);
1651+ }
1652+ print_hex_dump(KERN_ERR, "UNIPRO_TEST_BUS ", DUMP_PREFIX_OFFSET,
1653+ 16, 4, testbus, testbus_len, false);
1654+ kfree(testbus);
1655+}
1656+
16261657 static void ufs_qcom_dump_dbg_regs(struct ufs_hba *hba)
16271658 {
16281659 ufs_qcom_dump_regs(hba, REG_UFS_SYS1CLK_1US, 16,
16291660 "HCI Vendor Specific Registers ");
16301661
1662+ /* sleep a bit intermittently as we are dumping too much data */
16311663 ufs_qcom_print_hw_debug_reg_all(hba, NULL, ufs_qcom_dump_regs_wrapper);
1664+ usleep_range(1000, 1100);
16321665 ufs_qcom_testbus_read(hba);
1666+ usleep_range(1000, 1100);
1667+ ufs_qcom_print_unipro_testbus(hba);
1668+ usleep_range(1000, 1100);
16331669 }
16341670
16351671 /**
@@ -1692,6 +1728,7 @@ static const struct of_device_id ufs_qcom_of_match[] = { · 56 unmodified lines
16921728 { .compatible = "qcom,ufshc"},
16931729 {},
16941730 };
1731+MODULE_DEVICE_TABLE(of, ufs_qcom_of_match);
16951732
16961733 static const struct dev_pm_ops ufs_qcom_pm_ops = {
16971734 .suspend = ufshcd_pltfrm_suspend,
drivers/scsi/ufs/ufs-qcom.h+1−0
@@ -95,6 +95,7 @@ enum { · 94 unmodified lines
9595 #define QUNIPRO_SEL UFS_BIT(0)
9696 #define TEST_BUS_EN BIT(18)
9797 #define TEST_BUS_SEL GENMASK(22, 19)
98+#define UFS_REG_TEST_BUS_EN BIT(30)
9899
99100 /* bit definitions for REG_UFS_CFG2 register */
100101 #define UAWM_HW_CGC_EN (1 << 0)
drivers/scsi/ufs/ufs.h+12−0
@@ -523,4 +523,16 @@ struct ufs_dev_info { · 522 unmodified lines
523523 bool is_lu_power_on_wp;
524524 };
525525
526+#define MAX_MODEL_LEN 16
527+/**
528+ * ufs_dev_desc - ufs device details from the device descriptor
529+ *
530+ * @wmanufacturerid: card details
531+ * @model: card model
532+ */
533+struct ufs_dev_desc {
534+ u16 wmanufacturerid;
535+ char model[MAX_MODEL_LEN + 1];
536+};
537+
526538 #endif /* End of Header */
drivers/scsi/ufs/ufs_quirks.h+6−22
@@ -21,41 +21,28 @@ · 20 unmodified lines
2121 #define UFS_ANY_VENDOR 0xFFFF
2222 #define UFS_ANY_MODEL "ANY_MODEL"
2323
24−#define MAX_MODEL_LEN 16
25−
2624 #define UFS_VENDOR_TOSHIBA 0x198
2725 #define UFS_VENDOR_SAMSUNG 0x1CE
2826 #define UFS_VENDOR_SKHYNIX 0x1AD
2927
30−/**
31− * ufs_device_info - ufs device details
32− * @wmanufacturerid: card details
33− * @model: card model
34− */
35−struct ufs_device_info {
36− u16 wmanufacturerid;
37− char model[MAX_MODEL_LEN + 1];
38−};
39−
4028 /**
4129 * ufs_dev_fix - ufs device quirk info
4230 * @card: ufs card details
4331 * @quirk: device quirk
4432 */
4533 struct ufs_dev_fix {
46− struct ufs_device_info card;
34+ struct ufs_dev_desc card;
4735 unsigned int quirk;
4836 };
4937
5038 #define END_FIX { { 0 }, 0 }
5139
5240 /* add specific device quirk */
53−#define UFS_FIX(_vendor, _model, _quirk) \
54− { \
55− .card.wmanufacturerid = (_vendor),\
56− .card.model = (_model), \
57− .quirk = (_quirk), \
58− }
41+#define UFS_FIX(_vendor, _model, _quirk) { \
42+ .card.wmanufacturerid = (_vendor),\
43+ .card.model = (_model), \
44+ .quirk = (_quirk), \
45+}
5946
6047 /*
6148 * If UFS device is having issue in processing LCC (Line Control
@@ -144,7 +131,4 @@ struct ufs_dev_fix { · 82 unmodified lines
144131 */
145132 #define UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME (1 << 8)
146133
147−struct ufs_hba;
148−void ufs_advertise_fixup_device(struct ufs_hba *hba);
149−
150134 #endif /* UFS_QUIRKS_H_ */
drivers/scsi/ufs/ufshcd.c+1337−241
@@ -45,6 +45,9 @@ · 44 unmodified lines
4545 #include "ufs_quirks.h"
4646 #include "unipro.h"
4747
48+#define CREATE_TRACE_POINTS
49+#include <trace/events/ufs.h>
50+
4851 #define UFSHCD_REQ_SENSE_SIZE 18
4952
5053 #define UFSHCD_ENABLE_INTRS (UTP_TRANSFER_REQ_COMPL |\
@@ -94,6 +97,9 @@ · 43 unmodified lines
9497 _ret; \
9598 })
9699
100+#define ufshcd_hex_dump(prefix_str, buf, len) \
101+print_hex_dump(KERN_ERR, prefix_str, DUMP_PREFIX_OFFSET, 16, 4, buf, len, false)
102+
97103 static u32 ufs_query_desc_max_size[] = {
98104 QUERY_DESC_DEVICE_MAX_SIZE,
99105 QUERY_DESC_CONFIGURAION_MAX_SIZE,
@@ -185,6 +191,22 @@ ufs_get_pm_lvl_to_link_pwr_state(enum ufs_pm_level lvl) · 85 unmodified lines
185191 return ufs_pm_lvl_states[lvl].link_state;
186192 }
187193
194+static inline enum ufs_pm_level
195+ufs_get_desired_pm_lvl_for_dev_link_state(enum ufs_dev_pwr_mode dev_state,
196+ enum uic_link_state link_state)
197+{
198+ enum ufs_pm_level lvl;
199+
200+ for (lvl = UFS_PM_LVL_0; lvl < UFS_PM_LVL_MAX; lvl++) {
201+ if ((ufs_pm_lvl_states[lvl].dev_state == dev_state) &&
202+ (ufs_pm_lvl_states[lvl].link_state == link_state))
203+ return lvl;
204+ }
205+
206+ /* if no match found, return the level 0 */
207+ return UFS_PM_LVL_0;
208+}
209+
188210 static struct ufs_dev_fix ufs_fixups[] = {
189211 /* UFS cards deviations table */
190212 UFS_FIX(UFS_VENDOR_SAMSUNG, UFS_ANY_MODEL,
@@ -212,6 +234,7 @@ static struct ufs_dev_fix ufs_fixups[] = { · 21 unmodified lines
212234 static void ufshcd_tmc_handler(struct ufs_hba *hba);
213235 static void ufshcd_async_scan(void *data, async_cookie_t cookie);
214236 static int ufshcd_reset_and_restore(struct ufs_hba *hba);
237+static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd);
215238 static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag);
216239 static void ufshcd_hba_exit(struct ufs_hba *hba);
217240 static int ufshcd_probe_hba(struct ufs_hba *hba);
@@ -223,6 +246,10 @@ static int ufshcd_uic_hibern8_exit(struct ufs_hba *hba); · 5 unmodified lines
223246 static int ufshcd_uic_hibern8_enter(struct ufs_hba *hba);
224247 static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);
225248 static int ufshcd_host_reset_and_restore(struct ufs_hba *hba);
249+static void ufshcd_resume_clkscaling(struct ufs_hba *hba);
250+static void ufshcd_suspend_clkscaling(struct ufs_hba *hba);
251+static void __ufshcd_suspend_clkscaling(struct ufs_hba *hba);
252+static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up);
226253 static irqreturn_t ufshcd_intr(int irq, void *__hba);
227254 static int ufshcd_config_pwr_mode(struct ufs_hba *hba,
228255 struct ufs_pa_layer_attr *desired_pwr_mode);
@@ -267,6 +294,214 @@ static inline void ufshcd_remove_non_printable(char *val) · 38 unmodified lines
267294 *val = ' ';
268295 }
269296
297+static void ufshcd_add_command_trace(struct ufs_hba *hba,
298+ unsigned int tag, const char *str)
299+{
300+ sector_t lba = -1;
301+ u8 opcode = 0;
302+ u32 intr, doorbell;
303+ struct ufshcd_lrb *lrbp;
304+ int transfer_len = -1;
305+
306+ if (!trace_ufshcd_command_enabled())
307+ return;
308+
309+ lrbp = &hba->lrb[tag];
310+
311+ if (lrbp->cmd) { /* data phase exists */
312+ opcode = (u8)(*lrbp->cmd->cmnd);
313+ if ((opcode == READ_10) || (opcode == WRITE_10)) {
314+ /*
315+ * Currently we only fully trace read(10) and write(10)
316+ * commands
317+ */
318+ if (lrbp->cmd->request && lrbp->cmd->request->bio)
319+ lba =
320+ lrbp->cmd->request->bio->bi_iter.bi_sector;
321+ transfer_len = be32_to_cpu(
322+ lrbp->ucd_req_ptr->sc.exp_data_transfer_len);
323+ }
324+ }
325+
326+ intr = ufshcd_readl(hba, REG_INTERRUPT_STATUS);
327+ doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
328+ trace_ufshcd_command(dev_name(hba->dev), str, tag,
329+ doorbell, transfer_len, intr, lba, opcode);
330+}
331+
332+static void ufshcd_print_clk_freqs(struct ufs_hba *hba)
333+{
334+ struct ufs_clk_info *clki;
335+ struct list_head *head = &hba->clk_list_head;
336+
337+ if (!head || list_empty(head))
338+ return;
339+
340+ list_for_each_entry(clki, head, list) {
341+ if (!IS_ERR_OR_NULL(clki->clk) && clki->min_freq &&
342+ clki->max_freq)
343+ dev_err(hba->dev, "clk: %s, rate: %u\n",
344+ clki->name, clki->curr_freq);
345+ }
346+}
347+
348+static void ufshcd_print_uic_err_hist(struct ufs_hba *hba,
349+ struct ufs_uic_err_reg_hist *err_hist, char *err_name)
350+{
351+ int i;
352+
353+ for (i = 0; i < UIC_ERR_REG_HIST_LENGTH; i++) {
354+ int p = (i + err_hist->pos - 1) % UIC_ERR_REG_HIST_LENGTH;
355+
356+ if (err_hist->reg[p] == 0)
357+ continue;
358+ dev_err(hba->dev, "%s[%d] = 0x%x at %lld us\n", err_name, i,
359+ err_hist->reg[p], ktime_to_us(err_hist->tstamp[p]));
360+ }
361+}
362+
363+static void ufshcd_print_host_regs(struct ufs_hba *hba)
364+{
365+ /*
366+ * hex_dump reads its data without the readl macro. This might
367+ * cause inconsistency issues on some platform, as the printed
368+ * values may be from cache and not the most recent value.
369+ * To know whether you are looking at an un-cached version verify
370+ * that IORESOURCE_MEM flag is on when xxx_get_resource() is invoked
371+ * during platform/pci probe function.
372+ */
373+ ufshcd_hex_dump("host regs: ", hba->mmio_base, UFSHCI_REG_SPACE_SIZE);
374+ dev_err(hba->dev, "hba->ufs_version = 0x%x, hba->capabilities = 0x%x\n",
375+ hba->ufs_version, hba->capabilities);
376+ dev_err(hba->dev,
377+ "hba->outstanding_reqs = 0x%x, hba->outstanding_tasks = 0x%x\n",
378+ (u32)hba->outstanding_reqs, (u32)hba->outstanding_tasks);
379+ dev_err(hba->dev,
380+ "last_hibern8_exit_tstamp at %lld us, hibern8_exit_cnt = %d\n",
381+ ktime_to_us(hba->ufs_stats.last_hibern8_exit_tstamp),
382+ hba->ufs_stats.hibern8_exit_cnt);
383+
384+ ufshcd_print_uic_err_hist(hba, &hba->ufs_stats.pa_err, "pa_err");
385+ ufshcd_print_uic_err_hist(hba, &hba->ufs_stats.dl_err, "dl_err");
386+ ufshcd_print_uic_err_hist(hba, &hba->ufs_stats.nl_err, "nl_err");
387+ ufshcd_print_uic_err_hist(hba, &hba->ufs_stats.tl_err, "tl_err");
388+ ufshcd_print_uic_err_hist(hba, &hba->ufs_stats.dme_err, "dme_err");
389+
390+ ufshcd_print_clk_freqs(hba);
391+
392+ if (hba->vops && hba->vops->dbg_register_dump)
393+ hba->vops->dbg_register_dump(hba);
394+}
395+
396+static
397+void ufshcd_print_trs(struct ufs_hba *hba, unsigned long bitmap, bool pr_prdt)
398+{
399+ struct ufshcd_lrb *lrbp;
400+ int prdt_length;
401+ int tag;
402+
403+ for_each_set_bit(tag, &bitmap, hba->nutrs) {
404+ lrbp = &hba->lrb[tag];
405+
406+ dev_err(hba->dev, "UPIU[%d] - issue time %lld us\n",
407+ tag, ktime_to_us(lrbp->issue_time_stamp));
408+ dev_err(hba->dev,
409+ "UPIU[%d] - Transfer Request Descriptor phys@0x%llx\n",
410+ tag, (u64)lrbp->utrd_dma_addr);
411+
412+ ufshcd_hex_dump("UPIU TRD: ", lrbp->utr_descriptor_ptr,
413+ sizeof(struct utp_transfer_req_desc));
414+ dev_err(hba->dev, "UPIU[%d] - Request UPIU phys@0x%llx\n", tag,
415+ (u64)lrbp->ucd_req_dma_addr);
416+ ufshcd_hex_dump("UPIU REQ: ", lrbp->ucd_req_ptr,
417+ sizeof(struct utp_upiu_req));
418+ dev_err(hba->dev, "UPIU[%d] - Response UPIU phys@0x%llx\n", tag,
419+ (u64)lrbp->ucd_rsp_dma_addr);
420+ ufshcd_hex_dump("UPIU RSP: ", lrbp->ucd_rsp_ptr,
421+ sizeof(struct utp_upiu_rsp));
422+
423+ prdt_length = le16_to_cpu(
424+ lrbp->utr_descriptor_ptr->prd_table_length);
425+ dev_err(hba->dev,
426+ "UPIU[%d] - PRDT - %d entries phys@0x%llx\n",
427+ tag, prdt_length,
428+ (u64)lrbp->ucd_prdt_dma_addr);
429+
430+ if (pr_prdt)
431+ ufshcd_hex_dump("UPIU PRDT: ", lrbp->ucd_prdt_ptr,
432+ sizeof(struct ufshcd_sg_entry) * prdt_length);
433+ }
434+}
435+
436+static void ufshcd_print_tmrs(struct ufs_hba *hba, unsigned long bitmap)
437+{
438+ struct utp_task_req_desc *tmrdp;
439+ int tag;
440+
441+ for_each_set_bit(tag, &bitmap, hba->nutmrs) {
442+ tmrdp = &hba->utmrdl_base_addr[tag];
443+ dev_err(hba->dev, "TM[%d] - Task Management Header\n", tag);
444+ ufshcd_hex_dump("TM TRD: ", &tmrdp->header,
445+ sizeof(struct request_desc_header));
446+ dev_err(hba->dev, "TM[%d] - Task Management Request UPIU\n",
447+ tag);
448+ ufshcd_hex_dump("TM REQ: ", tmrdp->task_req_upiu,
449+ sizeof(struct utp_upiu_req));
450+ dev_err(hba->dev, "TM[%d] - Task Management Response UPIU\n",
451+ tag);
452+ ufshcd_hex_dump("TM RSP: ", tmrdp->task_rsp_upiu,
453+ sizeof(struct utp_task_req_desc));
454+ }
455+}
456+
457+static void ufshcd_print_host_state(struct ufs_hba *hba)
458+{
459+ dev_err(hba->dev, "UFS Host state=%d\n", hba->ufshcd_state);
460+ dev_err(hba->dev, "lrb in use=0x%lx, outstanding reqs=0x%lx tasks=0x%lx\n",
461+ hba->lrb_in_use, hba->outstanding_tasks, hba->outstanding_reqs);
462+ dev_err(hba->dev, "saved_err=0x%x, saved_uic_err=0x%x\n",
463+ hba->saved_err, hba->saved_uic_err);
464+ dev_err(hba->dev, "Device power mode=%d, UIC link state=%d\n",
465+ hba->curr_dev_pwr_mode, hba->uic_link_state);
466+ dev_err(hba->dev, "PM in progress=%d, sys. suspended=%d\n",
467+ hba->pm_op_in_progress, hba->is_sys_suspended);
468+ dev_err(hba->dev, "Auto BKOPS=%d, Host self-block=%d\n",
469+ hba->auto_bkops_enabled, hba->host->host_self_blocked);
470+ dev_err(hba->dev, "Clk gate=%d\n", hba->clk_gating.state);
471+ dev_err(hba->dev, "error handling flags=0x%x, req. abort count=%d\n",
472+ hba->eh_flags, hba->req_abort_count);
473+ dev_err(hba->dev, "Host capabilities=0x%x, caps=0x%x\n",
474+ hba->capabilities, hba->caps);
475+ dev_err(hba->dev, "quirks=0x%x, dev. quirks=0x%x\n", hba->quirks,
476+ hba->dev_quirks);
477+}
478+
479+/**
480+ * ufshcd_print_pwr_info - print power params as saved in hba
481+ * power info
482+ * @hba: per-adapter instance
483+ */
484+static void ufshcd_print_pwr_info(struct ufs_hba *hba)
485+{
486+ static const char * const names[] = {
487+ "INVALID MODE",
488+ "FAST MODE",
489+ "SLOW_MODE",
490+ "INVALID MODE",
491+ "FASTAUTO_MODE",
492+ "SLOWAUTO_MODE",
493+ "INVALID MODE",
494+ };
495+
496+ dev_err(hba->dev, "%s:[RX, TX]: gear=[%d, %d], lane[%d, %d], pwr[%s, %s], rate = %d\n",
497+ __func__,
498+ hba->pwr_info.gear_rx, hba->pwr_info.gear_tx,
499+ hba->pwr_info.lane_rx, hba->pwr_info.lane_tx,
500+ names[hba->pwr_info.pwr_rx],
501+ names[hba->pwr_info.pwr_tx],
502+ hba->pwr_info.hs_rate);
503+}
504+
270505 /*
271506 * ufshcd_wait_for_register - wait for register value to change
272507 * @hba - per-adapter interface
@@ -605,6 +840,28 @@ static inline int ufshcd_is_hba_active(struct ufs_hba *hba) · 332 unmodified lines
605840 return (ufshcd_readl(hba, REG_CONTROLLER_ENABLE) & 0x1) ? 0 : 1;
606841 }
607842
843+static const char *ufschd_uic_link_state_to_string(
844+ enum uic_link_state state)
845+{
846+ switch (state) {
847+ case UIC_LINK_OFF_STATE: return "OFF";
848+ case UIC_LINK_ACTIVE_STATE: return "ACTIVE";
849+ case UIC_LINK_HIBERN8_STATE: return "HIBERN8";
850+ default: return "UNKNOWN";
851+ }
852+}
853+
854+static const char *ufschd_ufs_dev_pwr_mode_to_string(
855+ enum ufs_dev_pwr_mode state)
856+{
857+ switch (state) {
858+ case UFS_ACTIVE_PWR_MODE: return "ACTIVE";
859+ case UFS_SLEEP_PWR_MODE: return "SLEEP";
860+ case UFS_POWERDOWN_PWR_MODE: return "POWERDOWN";
861+ default: return "UNKNOWN";
862+ }
863+}
864+
608865 u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba)
609866 {
610867 /* HCI version 1.0 and 1.1 supports UniPro 1.41 */
@@ -633,20 +890,523 @@ static bool ufshcd_is_unipro_pa_params_tuning_req(struct ufs_hba *hba) · 22 unmodified lines
633890 return false;
634891 }
635892
893+static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up)
894+{
895+ int ret = 0;
896+ struct ufs_clk_info *clki;
897+ struct list_head *head = &hba->clk_list_head;
898+ ktime_t start = ktime_get();
899+ bool clk_state_changed = false;
900+
901+ if (!head || list_empty(head))
902+ goto out;
903+
904+ ret = ufshcd_vops_clk_scale_notify(hba, scale_up, PRE_CHANGE);
905+ if (ret)
906+ return ret;
907+
908+ list_for_each_entry(clki, head, list) {
909+ if (!IS_ERR_OR_NULL(clki->clk)) {
910+ if (scale_up && clki->max_freq) {
911+ if (clki->curr_freq == clki->max_freq)
912+ continue;
913+
914+ clk_state_changed = true;
915+ ret = clk_set_rate(clki->clk, clki->max_freq);
916+ if (ret) {
917+ dev_err(hba->dev, "%s: %s clk set rate(%dHz) failed, %d\n",
918+ __func__, clki->name,
919+ clki->max_freq, ret);
920+ break;
921+ }
922+ trace_ufshcd_clk_scaling(dev_name(hba->dev),
923+ "scaled up", clki->name,
924+ clki->curr_freq,
925+ clki->max_freq);
926+
927+ clki->curr_freq = clki->max_freq;
928+
929+ } else if (!scale_up && clki->min_freq) {
930+ if (clki->curr_freq == clki->min_freq)
931+ continue;
932+
933+ clk_state_changed = true;
934+ ret = clk_set_rate(clki->clk, clki->min_freq);
935+ if (ret) {
936+ dev_err(hba->dev, "%s: %s clk set rate(%dHz) failed, %d\n",
937+ __func__, clki->name,
938+ clki->min_freq, ret);
939+ break;
940+ }
941+ trace_ufshcd_clk_scaling(dev_name(hba->dev),
942+ "scaled down", clki->name,
943+ clki->curr_freq,
944+ clki->min_freq);
945+ clki->curr_freq = clki->min_freq;
946+ }
947+ }
948+ dev_dbg(hba->dev, "%s: clk: %s, rate: %lu\n", __func__,
949+ clki->name, clk_get_rate(clki->clk));
950+ }
951+
952+ ret = ufshcd_vops_clk_scale_notify(hba, scale_up, POST_CHANGE);
953+
954+out:
955+ if (clk_state_changed)
956+ trace_ufshcd_profile_clk_scaling(dev_name(hba->dev),
957+ (scale_up ? "up" : "down"),
958+ ktime_to_us(ktime_sub(ktime_get(), start)), ret);
959+ return ret;
960+}
961+
962+/**
963+ * ufshcd_is_devfreq_scaling_required - check if scaling is required or not
964+ * @hba: per adapter instance
965+ * @scale_up: True if scaling up and false if scaling down
966+ *
967+ * Returns true if scaling is required, false otherwise.
968+ */
969+static bool ufshcd_is_devfreq_scaling_required(struct ufs_hba *hba,
970+ bool scale_up)
971+{
972+ struct ufs_clk_info *clki;
973+ struct list_head *head = &hba->clk_list_head;
974+
975+ if (!head || list_empty(head))
976+ return false;
977+
978+ list_for_each_entry(clki, head, list) {
979+ if (!IS_ERR_OR_NULL(clki->clk)) {
980+ if (scale_up && clki->max_freq) {
981+ if (clki->curr_freq == clki->max_freq)
982+ continue;
983+ return true;
984+ } else if (!scale_up && clki->min_freq) {
985+ if (clki->curr_freq == clki->min_freq)
986+ continue;
987+ return true;
988+ }
989+ }
990+ }
991+
992+ return false;
993+}
994+
995+static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba,
996+ u64 wait_timeout_us)
997+{
998+ unsigned long flags;
999+ int ret = 0;
1000+ u32 tm_doorbell;
1001+ u32 tr_doorbell;
1002+ bool timeout = false, do_last_check = false;
1003+ ktime_t start;
1004+
1005+ ufshcd_hold(hba, false);
1006+ spin_lock_irqsave(hba->host->host_lock, flags);
1007+ /*
1008+ * Wait for all the outstanding tasks/transfer requests.
1009+ * Verify by checking the doorbell registers are clear.
1010+ */
1011+ start = ktime_get();
1012+ do {
1013+ if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) {
1014+ ret = -EBUSY;
1015+ goto out;
1016+ }
1017+
1018+ tm_doorbell = ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL);
1019+ tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
1020+ if (!tm_doorbell && !tr_doorbell) {
1021+ timeout = false;
1022+ break;
1023+ } else if (do_last_check) {
1024+ break;
1025+ }
1026+
1027+ spin_unlock_irqrestore(hba->host->host_lock, flags);
1028+ schedule();
1029+ if (ktime_to_us(ktime_sub(ktime_get(), start)) >
1030+ wait_timeout_us) {
1031+ timeout = true;
1032+ /*
1033+ * We might have scheduled out for long time so make
1034+ * sure to check if doorbells are cleared by this time
1035+ * or not.
1036+ */
1037+ do_last_check = true;
1038+ }
1039+ spin_lock_irqsave(hba->host->host_lock, flags);
1040+ } while (tm_doorbell || tr_doorbell);
1041+
1042+ if (timeout) {
1043+ dev_err(hba->dev,
1044+ "%s: timedout waiting for doorbell to clear (tm=0x%x, tr=0x%x)\n",
1045+ __func__, tm_doorbell, tr_doorbell);
1046+ ret = -EBUSY;
1047+ }
1048+out:
1049+ spin_unlock_irqrestore(hba->host->host_lock, flags);
1050+ ufshcd_release(hba);
1051+ return ret;
1052+}
1053+
1054+/**
1055+ * ufshcd_scale_gear - scale up/down UFS gear
1056+ * @hba: per adapter instance
1057+ * @scale_up: True for scaling up gear and false for scaling down
1058+ *
1059+ * Returns 0 for success,
1060+ * Returns -EBUSY if scaling can't happen at this time
1061+ * Returns non-zero for any other errors
1062+ */
1063+static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up)
1064+{
1065+ #define UFS_MIN_GEAR_TO_SCALE_DOWN UFS_HS_G1
1066+ int ret = 0;
1067+ struct ufs_pa_layer_attr new_pwr_info;
1068+
1069+ if (scale_up) {
1070+ memcpy(&new_pwr_info, &hba->clk_scaling.saved_pwr_info.info,
1071+ sizeof(struct ufs_pa_layer_attr));
1072+ } else {
1073+ memcpy(&new_pwr_info, &hba->pwr_info,
1074+ sizeof(struct ufs_pa_layer_attr));
1075+
1076+ if (hba->pwr_info.gear_tx > UFS_MIN_GEAR_TO_SCALE_DOWN
1077+ || hba->pwr_info.gear_rx > UFS_MIN_GEAR_TO_SCALE_DOWN) {
1078+ /* save the current power mode */
1079+ memcpy(&hba->clk_scaling.saved_pwr_info.info,
1080+ &hba->pwr_info,
1081+ sizeof(struct ufs_pa_layer_attr));
1082+
1083+ /* scale down gear */
1084+ new_pwr_info.gear_tx = UFS_MIN_GEAR_TO_SCALE_DOWN;
1085+ new_pwr_info.gear_rx = UFS_MIN_GEAR_TO_SCALE_DOWN;
1086+ }
1087+ }
1088+
1089+ /* check if the power mode needs to be changed or not? */
1090+ ret = ufshcd_change_power_mode(hba, &new_pwr_info);
1091+
1092+ if (ret)
1093+ dev_err(hba->dev, "%s: failed err %d, old gear: (tx %d rx %d), new gear: (tx %d rx %d)",
1094+ __func__, ret,
1095+ hba->pwr_info.gear_tx, hba->pwr_info.gear_rx,
1096+ new_pwr_info.gear_tx, new_pwr_info.gear_rx);
1097+
1098+ return ret;
1099+}
1100+
1101+static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba)
1102+{
1103+ #define DOORBELL_CLR_TOUT_US (1000 * 1000) /* 1 sec */
1104+ int ret = 0;
1105+ /*
1106+ * make sure that there are no outstanding requests when
1107+ * clock scaling is in progress
1108+ */
1109+ scsi_block_requests(hba->host);
1110+ down_write(&hba->clk_scaling_lock);
1111+ if (ufshcd_wait_for_doorbell_clr(hba, DOORBELL_CLR_TOUT_US)) {
1112+ ret = -EBUSY;
1113+ up_write(&hba->clk_scaling_lock);
1114+ scsi_unblock_requests(hba->host);
1115+ }
1116+
1117+ return ret;
1118+}
1119+
1120+static void ufshcd_clock_scaling_unprepare(struct ufs_hba *hba)
1121+{
1122+ up_write(&hba->clk_scaling_lock);
1123+ scsi_unblock_requests(hba->host);
1124+}
1125+
1126+/**
1127+ * ufshcd_devfreq_scale - scale up/down UFS clocks and gear
1128+ * @hba: per adapter instance
1129+ * @scale_up: True for scaling up and false for scalin down
1130+ *
1131+ * Returns 0 for success,
1132+ * Returns -EBUSY if scaling can't happen at this time
1133+ * Returns non-zero for any other errors
1134+ */
1135+static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up)
1136+{
1137+ int ret = 0;
1138+
1139+ /* let's not get into low power until clock scaling is completed */
1140+ ufshcd_hold(hba, false);
1141+
1142+ ret = ufshcd_clock_scaling_prepare(hba);
1143+ if (ret)
1144+ return ret;
1145+
1146+ /* scale down the gear before scaling down clocks */
1147+ if (!scale_up) {
1148+ ret = ufshcd_scale_gear(hba, false);
1149+ if (ret)
1150+ goto out;
1151+ }
1152+
1153+ ret = ufshcd_scale_clks(hba, scale_up);
1154+ if (ret) {
1155+ if (!scale_up)
1156+ ufshcd_scale_gear(hba, true);
1157+ goto out;
1158+ }
1159+
1160+ /* scale up the gear after scaling up clocks */
1161+ if (scale_up) {
1162+ ret = ufshcd_scale_gear(hba, true);
1163+ if (ret) {
1164+ ufshcd_scale_clks(hba, false);
1165+ goto out;
1166+ }
1167+ }
1168+
1169+ ret = ufshcd_vops_clk_scale_notify(hba, scale_up, POST_CHANGE);
1170+
1171+out:
1172+ ufshcd_clock_scaling_unprepare(hba);
1173+ ufshcd_release(hba);
1174+ return ret;
1175+}
1176+
1177+static void ufshcd_clk_scaling_suspend_work(struct work_struct *work)
1178+{
1179+ struct ufs_hba *hba = container_of(work, struct ufs_hba,
1180+ clk_scaling.suspend_work);
1181+ unsigned long irq_flags;
1182+
1183+ spin_lock_irqsave(hba->host->host_lock, irq_flags);
1184+ if (hba->clk_scaling.active_reqs || hba->clk_scaling.is_suspended) {
1185+ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
1186+ return;
1187+ }
1188+ hba->clk_scaling.is_suspended = true;
1189+ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
1190+
1191+ __ufshcd_suspend_clkscaling(hba);
1192+}
1193+
1194+static void ufshcd_clk_scaling_resume_work(struct work_struct *work)
1195+{
1196+ struct ufs_hba *hba = container_of(work, struct ufs_hba,
1197+ clk_scaling.resume_work);
1198+ unsigned long irq_flags;
1199+
1200+ spin_lock_irqsave(hba->host->host_lock, irq_flags);
1201+ if (!hba->clk_scaling.is_suspended) {
1202+ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
1203+ return;
1204+ }
1205+ hba->clk_scaling.is_suspended = false;
1206+ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
1207+
1208+ devfreq_resume_device(hba->devfreq);
1209+}
1210+
1211+static int ufshcd_devfreq_target(struct device *dev,
1212+ unsigned long *freq, u32 flags)
1213+{
1214+ int ret = 0;
1215+ struct ufs_hba *hba = dev_get_drvdata(dev);
1216+ ktime_t start;
1217+ bool scale_up, sched_clk_scaling_suspend_work = false;
1218+ unsigned long irq_flags;
1219+
1220+ if (!ufshcd_is_clkscaling_supported(hba))
1221+ return -EINVAL;
1222+
1223+ if ((*freq > 0) && (*freq < UINT_MAX)) {
1224+ dev_err(hba->dev, "%s: invalid freq = %lu\n", __func__, *freq);
1225+ return -EINVAL;
1226+ }
1227+
1228+ spin_lock_irqsave(hba->host->host_lock, irq_flags);
1229+ if (ufshcd_eh_in_progress(hba)) {
1230+ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
1231+ return 0;
1232+ }
1233+
1234+ if (!hba->clk_scaling.active_reqs)
1235+ sched_clk_scaling_suspend_work = true;
1236+
1237+ scale_up = (*freq == UINT_MAX) ? true : false;
1238+ if (!ufshcd_is_devfreq_scaling_required(hba, scale_up)) {
1239+ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
1240+ ret = 0;
1241+ goto out; /* no state change required */
1242+ }
1243+ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
1244+
1245+ start = ktime_get();
1246+ ret = ufshcd_devfreq_scale(hba, scale_up);
1247+
1248+ trace_ufshcd_profile_clk_scaling(dev_name(hba->dev),
1249+ (scale_up ? "up" : "down"),
1250+ ktime_to_us(ktime_sub(ktime_get(), start)), ret);
1251+
1252+out:
1253+ if (sched_clk_scaling_suspend_work)
1254+ queue_work(hba->clk_scaling.workq,
1255+ &hba->clk_scaling.suspend_work);
1256+
1257+ return ret;
1258+}
1259+
1260+
1261+static int ufshcd_devfreq_get_dev_status(struct device *dev,
1262+ struct devfreq_dev_status *stat)
1263+{
1264+ struct ufs_hba *hba = dev_get_drvdata(dev);
1265+ struct ufs_clk_scaling *scaling = &hba->clk_scaling;
1266+ unsigned long flags;
1267+
1268+ if (!ufshcd_is_clkscaling_supported(hba))
1269+ return -EINVAL;
1270+
1271+ memset(stat, 0, sizeof(*stat));
1272+
1273+ spin_lock_irqsave(hba->host->host_lock, flags);
1274+ if (!scaling->window_start_t)
1275+ goto start_window;
1276+
1277+ if (scaling->is_busy_started)
1278+ scaling->tot_busy_t += ktime_to_us(ktime_sub(ktime_get(),
1279+ scaling->busy_start_t));
1280+
1281+ stat->total_time = jiffies_to_usecs((long)jiffies -
1282+ (long)scaling->window_start_t);
1283+ stat->busy_time = scaling->tot_busy_t;
1284+start_window:
1285+ scaling->window_start_t = jiffies;
1286+ scaling->tot_busy_t = 0;
1287+
1288+ if (hba->outstanding_reqs) {
1289+ scaling->busy_start_t = ktime_get();
1290+ scaling->is_busy_started = true;
1291+ } else {
1292+ scaling->busy_start_t = 0;
1293+ scaling->is_busy_started = false;
1294+ }
1295+ spin_unlock_irqrestore(hba->host->host_lock, flags);
1296+ return 0;
1297+}
1298+
1299+static struct devfreq_dev_profile ufs_devfreq_profile = {
1300+ .polling_ms = 100,
1301+ .target = ufshcd_devfreq_target,
1302+ .get_dev_status = ufshcd_devfreq_get_dev_status,
1303+};
1304+
1305+static void __ufshcd_suspend_clkscaling(struct ufs_hba *hba)
1306+{
1307+ unsigned long flags;
1308+
1309+ devfreq_suspend_device(hba->devfreq);
1310+ spin_lock_irqsave(hba->host->host_lock, flags);
1311+ hba->clk_scaling.window_start_t = 0;
1312+ spin_unlock_irqrestore(hba->host->host_lock, flags);
1313+}
1314+
6361315 static void ufshcd_suspend_clkscaling(struct ufs_hba *hba)
6371316 {
638− if (ufshcd_is_clkscaling_enabled(hba)) {
639− devfreq_suspend_device(hba->devfreq);
640− hba->clk_scaling.window_start_t = 0;
1317+ unsigned long flags;
1318+ bool suspend = false;
1319+
1320+ if (!ufshcd_is_clkscaling_supported(hba))
1321+ return;
1322+
1323+ spin_lock_irqsave(hba->host->host_lock, flags);
1324+ if (!hba->clk_scaling.is_suspended) {
1325+ suspend = true;
1326+ hba->clk_scaling.is_suspended = true;
6411327 }
1328+ spin_unlock_irqrestore(hba->host->host_lock, flags);
1329+
1330+ if (suspend)
1331+ __ufshcd_suspend_clkscaling(hba);
6421332 }
6431333
6441334 static void ufshcd_resume_clkscaling(struct ufs_hba *hba)
6451335 {
646− if (ufshcd_is_clkscaling_enabled(hba))
1336+ unsigned long flags;
1337+ bool resume = false;
1338+
1339+ if (!ufshcd_is_clkscaling_supported(hba))
1340+ return;
1341+
1342+ spin_lock_irqsave(hba->host->host_lock, flags);
1343+ if (hba->clk_scaling.is_suspended) {
1344+ resume = true;
1345+ hba->clk_scaling.is_suspended = false;
1346+ }
1347+ spin_unlock_irqrestore(hba->host->host_lock, flags);
1348+
1349+ if (resume)
6471350 devfreq_resume_device(hba->devfreq);
6481351 }
6491352
1353+static ssize_t ufshcd_clkscale_enable_show(struct device *dev,
1354+ struct device_attribute *attr, char *buf)
1355+{
1356+ struct ufs_hba *hba = dev_get_drvdata(dev);
1357+
1358+ return snprintf(buf, PAGE_SIZE, "%d\n", hba->clk_scaling.is_allowed);
1359+}
1360+
1361+static ssize_t ufshcd_clkscale_enable_store(struct device *dev,
1362+ struct device_attribute *attr, const char *buf, size_t count)
1363+{
1364+ struct ufs_hba *hba = dev_get_drvdata(dev);
1365+ u32 value;
1366+ int err;
1367+
1368+ if (kstrtou32(buf, 0, &value))
1369+ return -EINVAL;
1370+
1371+ value = !!value;
1372+ if (value == hba->clk_scaling.is_allowed)
1373+ goto out;
1374+
1375+ pm_runtime_get_sync(hba->dev);
1376+ ufshcd_hold(hba, false);
1377+
1378+ cancel_work_sync(&hba->clk_scaling.suspend_work);
1379+ cancel_work_sync(&hba->clk_scaling.resume_work);
1380+
1381+ hba->clk_scaling.is_allowed = value;
1382+
1383+ if (value) {
1384+ ufshcd_resume_clkscaling(hba);
1385+ } else {
1386+ ufshcd_suspend_clkscaling(hba);
1387+ err = ufshcd_devfreq_scale(hba, true);
1388+ if (err)
1389+ dev_err(hba->dev, "%s: failed to scale clocks up %d\n",
1390+ __func__, err);
1391+ }
1392+
1393+ ufshcd_release(hba);
1394+ pm_runtime_put_sync(hba->dev);
1395+out:
1396+ return count;
1397+}
1398+
1399+static void ufshcd_clkscaling_init_sysfs(struct ufs_hba *hba)
1400+{
1401+ hba->clk_scaling.enable_attr.show = ufshcd_clkscale_enable_show;
1402+ hba->clk_scaling.enable_attr.store = ufshcd_clkscale_enable_store;
1403+ sysfs_attr_init(&hba->clk_scaling.enable_attr.attr);
1404+ hba->clk_scaling.enable_attr.attr.name = "clkscale_enable";
1405+ hba->clk_scaling.enable_attr.attr.mode = 0644;
1406+ if (device_create_file(hba->dev, &hba->clk_scaling.enable_attr))
1407+ dev_err(hba->dev, "Failed to create sysfs for clkscale_enable\n");
1408+}
1409+
6501410 static void ufshcd_ungate_work(struct work_struct *work)
6511411 {
6521412 int ret;
@@ -680,7 +1440,6 @@ static void ufshcd_ungate_work(struct work_struct *work) · 27 unmodified lines
6801440 hba->clk_gating.is_suspended = false;
6811441 }
6821442 unblock_reqs:
683− ufshcd_resume_clkscaling(hba);
6841443 scsi_unblock_requests(hba->host);
6851444 }
6861445
@@ -727,6 +1486,8 @@ start: · 40 unmodified lines
7271486 case REQ_CLKS_OFF:
7281487 if (cancel_delayed_work(&hba->clk_gating.gate_work)) {
7291488 hba->clk_gating.state = CLKS_ON;
1489+ trace_ufshcd_clk_gating(dev_name(hba->dev),
1490+ hba->clk_gating.state);
7301491 break;
7311492 }
7321493 /*
@@ -737,6 +1498,8 @@ start: · 4 unmodified lines
7371498 case CLKS_OFF:
7381499 scsi_block_requests(hba->host);
7391500 hba->clk_gating.state = REQ_CLKS_ON;
1501+ trace_ufshcd_clk_gating(dev_name(hba->dev),
1502+ hba->clk_gating.state);
7401503 schedule_work(&hba->clk_gating.ungate_work);
7411504 /*
7421505 * fall through to check if we should wait for this
@@ -781,6 +1544,8 @@ static void ufshcd_gate_work(struct work_struct *work) · 38 unmodified lines
7811544 if (hba->clk_gating.is_suspended ||
7821545 (hba->clk_gating.state == REQ_CLKS_ON)) {
7831546 hba->clk_gating.state = CLKS_ON;
1547+ trace_ufshcd_clk_gating(dev_name(hba->dev),
1548+ hba->clk_gating.state);
7841549 goto rel_lock;
7851550 }
7861551
@@ -796,13 +1561,13 @@ static void ufshcd_gate_work(struct work_struct *work) · 9 unmodified lines
7961561 if (ufshcd_can_hibern8_during_gating(hba)) {
7971562 if (ufshcd_uic_hibern8_enter(hba)) {
7981563 hba->clk_gating.state = CLKS_ON;
1564+ trace_ufshcd_clk_gating(dev_name(hba->dev),
1565+ hba->clk_gating.state);
7991566 goto out;
8001567 }
8011568 ufshcd_set_link_hibern8(hba);
8021569 }
8031570
804− ufshcd_suspend_clkscaling(hba);
805−
8061571 if (!ufshcd_is_link_active(hba))
8071572 ufshcd_setup_clocks(hba, false);
8081573 else
@@ -819,9 +1584,11 @@ static void ufshcd_gate_work(struct work_struct *work) · 10 unmodified lines
8191584 * new requests arriving before the current cancel work is done.
8201585 */
8211586 spin_lock_irqsave(hba->host->host_lock, flags);
822− if (hba->clk_gating.state == REQ_CLKS_OFF)
1587+ if (hba->clk_gating.state == REQ_CLKS_OFF) {
8231588 hba->clk_gating.state = CLKS_OFF;
824−
1589+ trace_ufshcd_clk_gating(dev_name(hba->dev),
1590+ hba->clk_gating.state);
1591+ }
8251592 rel_lock:
8261593 spin_unlock_irqrestore(hba->host->host_lock, flags);
8271594 out:
@@ -844,6 +1611,7 @@ static void __ufshcd_release(struct ufs_hba *hba) · 16 unmodified lines
8441611 return;
8451612
8461613 hba->clk_gating.state = REQ_CLKS_OFF;
1614+ trace_ufshcd_clk_gating(dev_name(hba->dev), hba->clk_gating.state);
8471615 schedule_delayed_work(&hba->clk_gating.gate_work,
8481616 msecs_to_jiffies(hba->clk_gating.delay_ms));
8491617 }
@@ -881,6 +1649,41 @@ static ssize_t ufshcd_clkgate_delay_store(struct device *dev, · 31 unmodified lines
8811649 return count;
8821650 }
8831651
1652+static ssize_t ufshcd_clkgate_enable_show(struct device *dev,
1653+ struct device_attribute *attr, char *buf)
1654+{
1655+ struct ufs_hba *hba = dev_get_drvdata(dev);
1656+
1657+ return snprintf(buf, PAGE_SIZE, "%d\n", hba->clk_gating.is_enabled);
1658+}
1659+
1660+static ssize_t ufshcd_clkgate_enable_store(struct device *dev,
1661+ struct device_attribute *attr, const char *buf, size_t count)
1662+{
1663+ struct ufs_hba *hba = dev_get_drvdata(dev);
1664+ unsigned long flags;
1665+ u32 value;
1666+
1667+ if (kstrtou32(buf, 0, &value))
1668+ return -EINVAL;
1669+
1670+ value = !!value;
1671+ if (value == hba->clk_gating.is_enabled)
1672+ goto out;
1673+
1674+ if (value) {
1675+ ufshcd_release(hba);
1676+ } else {
1677+ spin_lock_irqsave(hba->host->host_lock, flags);
1678+ hba->clk_gating.active_reqs++;
1679+ spin_unlock_irqrestore(hba->host->host_lock, flags);
1680+ }
1681+
1682+ hba->clk_gating.is_enabled = value;
1683+out:
1684+ return count;
1685+}
1686+
8841687 static void ufshcd_init_clk_gating(struct ufs_hba *hba)
8851688 {
8861689 if (!ufshcd_is_clkgating_allowed(hba))
@@ -890,13 +1693,23 @@ static void ufshcd_init_clk_gating(struct ufs_hba *hba) · 3 unmodified lines
8901693 INIT_DELAYED_WORK(&hba->clk_gating.gate_work, ufshcd_gate_work);
8911694 INIT_WORK(&hba->clk_gating.ungate_work, ufshcd_ungate_work);
8921695
1696+ hba->clk_gating.is_enabled = true;
1697+
8931698 hba->clk_gating.delay_attr.show = ufshcd_clkgate_delay_show;
8941699 hba->clk_gating.delay_attr.store = ufshcd_clkgate_delay_store;
8951700 sysfs_attr_init(&hba->clk_gating.delay_attr.attr);
8961701 hba->clk_gating.delay_attr.attr.name = "clkgate_delay_ms";
897− hba->clk_gating.delay_attr.attr.mode = S_IRUGO | S_IWUSR;
1702+ hba->clk_gating.delay_attr.attr.mode = 0644;
8981703 if (device_create_file(hba->dev, &hba->clk_gating.delay_attr))
8991704 dev_err(hba->dev, "Failed to create sysfs for clkgate_delay\n");
1705+

1406 more lines aren’t shown here.

drivers/scsi/ufs/ufshcd.h+110−11

This diff is large: its 245 lines aren’t shown here.

drivers/scsi/ufs/ufshci.h+3−0

This diff is large: its 10 lines aren’t shown here.

drivers/scsi/vmw_pvscsi.c+38−66

This diff is large: its 158 lines aren’t shown here.

drivers/scsi/vmw_pvscsi.h+0−5

This diff is large: its 12 lines aren’t shown here.

include/linux/libata.h+2−0

This diff is large: its 16 lines aren’t shown here.

include/scsi/libiscsi.h+1−0

This diff is large: its 8 lines aren’t shown here.

include/scsi/scsi.h+0−10

This diff is large: its 17 lines aren’t shown here.

include/scsi/scsi_transport.h+0−23

This diff is large: its 30 lines aren’t shown here.

include/scsi/scsi_transport_fc.h+1−0

This diff is large: its 8 lines aren’t shown here.

include/scsi/scsi_transport_srp.h+1−7

This diff is large: its 29 lines aren’t shown here.

include/trace/events/ufs.h+263−0

This diff is large: its 264 lines aren’t shown here.

include/uapi/scsi/cxlflash_ioctl.h+1−0

This diff is large: its 8 lines aren’t shown here.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t