zfcp_fc.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * zfcp device driver
  3. *
  4. * Fibre Channel related definitions and inline functions for the zfcp
  5. * device driver
  6. *
  7. * Copyright IBM Corporation 2009
  8. */
  9. #ifndef ZFCP_FC_H
  10. #define ZFCP_FC_H
  11. #include <scsi/fc/fc_fcp.h>
  12. #include <scsi/scsi_cmnd.h>
  13. #include <scsi/scsi_tcq.h>
  14. /**
  15. * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
  16. * @fcp: fcp_cmnd to setup
  17. * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
  18. */
  19. static inline
  20. void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
  21. {
  22. char tag[2];
  23. int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
  24. if (scsi_populate_tag_msg(scsi, tag)) {
  25. switch (tag[0]) {
  26. case MSG_ORDERED_TAG:
  27. fcp->fc_pri_ta |= FCP_PTA_ORDERED;
  28. break;
  29. case MSG_SIMPLE_TAG:
  30. fcp->fc_pri_ta |= FCP_PTA_SIMPLE;
  31. break;
  32. };
  33. } else
  34. fcp->fc_pri_ta = FCP_PTA_SIMPLE;
  35. if (scsi->sc_data_direction == DMA_FROM_DEVICE)
  36. fcp->fc_flags |= FCP_CFL_RDDATA;
  37. if (scsi->sc_data_direction == DMA_TO_DEVICE)
  38. fcp->fc_flags |= FCP_CFL_WRDATA;
  39. memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len);
  40. fcp->fc_dl = scsi_bufflen(scsi);
  41. }
  42. /**
  43. * zfcp_fc_fcp_tm - setup FCP command as task management command
  44. * @fcp: fcp_cmnd to setup
  45. * @dev: scsi_device where to send the task management command
  46. * @tm: task management flags to setup tm command
  47. */
  48. static inline
  49. void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
  50. {
  51. int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
  52. fcp->fc_tm_flags |= tm_flags;
  53. }
  54. /**
  55. * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
  56. * @fcp_rsp: FCP RSP IU to evaluate
  57. * @scsi: SCSI command where to update status and sense buffer
  58. */
  59. static inline
  60. void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
  61. struct scsi_cmnd *scsi)
  62. {
  63. struct fcp_resp_rsp_info *rsp_info;
  64. char *sense;
  65. u32 sense_len, resid;
  66. u8 rsp_flags;
  67. set_msg_byte(scsi, COMMAND_COMPLETE);
  68. scsi->result |= fcp_rsp->resp.fr_status;
  69. rsp_flags = fcp_rsp->resp.fr_flags;
  70. if (unlikely(rsp_flags & FCP_RSP_LEN_VAL)) {
  71. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  72. if (rsp_info->rsp_code == FCP_TMF_CMPL)
  73. set_host_byte(scsi, DID_OK);
  74. else {
  75. set_host_byte(scsi, DID_ERROR);
  76. return;
  77. }
  78. }
  79. if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
  80. sense = (char *) &fcp_rsp[1];
  81. if (rsp_flags & FCP_RSP_LEN_VAL)
  82. sense += fcp_rsp->ext.fr_sns_len;
  83. sense_len = min(fcp_rsp->ext.fr_sns_len,
  84. (u32) SCSI_SENSE_BUFFERSIZE);
  85. memcpy(scsi->sense_buffer, sense, sense_len);
  86. }
  87. if (unlikely(rsp_flags & FCP_RESID_UNDER)) {
  88. resid = fcp_rsp->ext.fr_resid;
  89. scsi_set_resid(scsi, resid);
  90. if (scsi_bufflen(scsi) - resid < scsi->underflow &&
  91. !(rsp_flags & FCP_SNS_LEN_VAL) &&
  92. fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
  93. set_host_byte(scsi, DID_ERROR);
  94. }
  95. }
  96. #endif