ql4_isr.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include "ql4_def.h"
  8. #include "ql4_glbl.h"
  9. #include "ql4_dbg.h"
  10. #include "ql4_inline.h"
  11. /**
  12. * qla4xxx_copy_sense - copy sense data into cmd sense buffer
  13. * @ha: Pointer to host adapter structure.
  14. * @sts_entry: Pointer to status entry structure.
  15. * @srb: Pointer to srb structure.
  16. **/
  17. static void qla4xxx_copy_sense(struct scsi_qla_host *ha,
  18. struct status_entry *sts_entry,
  19. struct srb *srb)
  20. {
  21. struct scsi_cmnd *cmd = srb->cmd;
  22. uint16_t sense_len;
  23. memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  24. sense_len = le16_to_cpu(sts_entry->senseDataByteCnt);
  25. if (sense_len == 0) {
  26. DEBUG2(ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%d:%d: %s:"
  27. " sense len 0\n", ha->host_no,
  28. cmd->device->channel, cmd->device->id,
  29. cmd->device->lun, __func__));
  30. ha->status_srb = NULL;
  31. return;
  32. }
  33. /* Save total available sense length,
  34. * not to exceed cmd's sense buffer size */
  35. sense_len = min_t(uint16_t, sense_len, SCSI_SENSE_BUFFERSIZE);
  36. srb->req_sense_ptr = cmd->sense_buffer;
  37. srb->req_sense_len = sense_len;
  38. /* Copy sense from sts_entry pkt */
  39. sense_len = min_t(uint16_t, sense_len, IOCB_MAX_SENSEDATA_LEN);
  40. memcpy(cmd->sense_buffer, sts_entry->senseData, sense_len);
  41. DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: %s: sense key = %x, "
  42. "ASL= %02x, ASC/ASCQ = %02x/%02x\n", ha->host_no,
  43. cmd->device->channel, cmd->device->id,
  44. cmd->device->lun, __func__,
  45. sts_entry->senseData[2] & 0x0f,
  46. sts_entry->senseData[7],
  47. sts_entry->senseData[12],
  48. sts_entry->senseData[13]));
  49. DEBUG5(qla4xxx_dump_buffer(cmd->sense_buffer, sense_len));
  50. srb->flags |= SRB_GOT_SENSE;
  51. /* Update srb, in case a sts_cont pkt follows */
  52. srb->req_sense_ptr += sense_len;
  53. srb->req_sense_len -= sense_len;
  54. if (srb->req_sense_len != 0)
  55. ha->status_srb = srb;
  56. else
  57. ha->status_srb = NULL;
  58. }
  59. /**
  60. * qla4xxx_status_cont_entry - Process a Status Continuations entry.
  61. * @ha: SCSI driver HA context
  62. * @sts_cont: Entry pointer
  63. *
  64. * Extended sense data.
  65. */
  66. static void
  67. qla4xxx_status_cont_entry(struct scsi_qla_host *ha,
  68. struct status_cont_entry *sts_cont)
  69. {
  70. struct srb *srb = ha->status_srb;
  71. struct scsi_cmnd *cmd;
  72. uint16_t sense_len;
  73. if (srb == NULL)
  74. return;
  75. cmd = srb->cmd;
  76. if (cmd == NULL) {
  77. DEBUG2(printk(KERN_INFO "scsi%ld: %s: Cmd already returned "
  78. "back to OS srb=%p srb->state:%d\n", ha->host_no,
  79. __func__, srb, srb->state));
  80. ha->status_srb = NULL;
  81. return;
  82. }
  83. /* Copy sense data. */
  84. sense_len = min_t(uint16_t, srb->req_sense_len,
  85. IOCB_MAX_EXT_SENSEDATA_LEN);
  86. memcpy(srb->req_sense_ptr, sts_cont->ext_sense_data, sense_len);
  87. DEBUG5(qla4xxx_dump_buffer(srb->req_sense_ptr, sense_len));
  88. srb->req_sense_ptr += sense_len;
  89. srb->req_sense_len -= sense_len;
  90. /* Place command on done queue. */
  91. if (srb->req_sense_len == 0) {
  92. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  93. ha->status_srb = NULL;
  94. }
  95. }
  96. /**
  97. * qla4xxx_status_entry - processes status IOCBs
  98. * @ha: Pointer to host adapter structure.
  99. * @sts_entry: Pointer to status entry structure.
  100. **/
  101. static void qla4xxx_status_entry(struct scsi_qla_host *ha,
  102. struct status_entry *sts_entry)
  103. {
  104. uint8_t scsi_status;
  105. struct scsi_cmnd *cmd;
  106. struct srb *srb;
  107. struct ddb_entry *ddb_entry;
  108. uint32_t residual;
  109. srb = qla4xxx_del_from_active_array(ha, le32_to_cpu(sts_entry->handle));
  110. if (!srb) {
  111. ql4_printk(KERN_WARNING, ha, "%s invalid status entry: "
  112. "handle=0x%0x, srb=%p\n", __func__,
  113. sts_entry->handle, srb);
  114. if (is_qla80XX(ha))
  115. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  116. else
  117. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  118. return;
  119. }
  120. cmd = srb->cmd;
  121. if (cmd == NULL) {
  122. DEBUG2(printk("scsi%ld: %s: Command already returned back to "
  123. "OS pkt->handle=%d srb=%p srb->state:%d\n",
  124. ha->host_no, __func__, sts_entry->handle,
  125. srb, srb->state));
  126. ql4_printk(KERN_WARNING, ha, "Command is NULL:"
  127. " already returned to OS (srb=%p)\n", srb);
  128. return;
  129. }
  130. ddb_entry = srb->ddb;
  131. if (ddb_entry == NULL) {
  132. cmd->result = DID_NO_CONNECT << 16;
  133. goto status_entry_exit;
  134. }
  135. residual = le32_to_cpu(sts_entry->residualByteCnt);
  136. /* Translate ISP error to a Linux SCSI error. */
  137. scsi_status = sts_entry->scsiStatus;
  138. switch (sts_entry->completionStatus) {
  139. case SCS_COMPLETE:
  140. if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
  141. cmd->result = DID_ERROR << 16;
  142. break;
  143. }
  144. if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
  145. scsi_set_resid(cmd, residual);
  146. if (!scsi_status && ((scsi_bufflen(cmd) - residual) <
  147. cmd->underflow)) {
  148. cmd->result = DID_ERROR << 16;
  149. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
  150. "Mid-layer Data underrun0, "
  151. "xferlen = 0x%x, "
  152. "residual = 0x%x\n", ha->host_no,
  153. cmd->device->channel,
  154. cmd->device->id,
  155. cmd->device->lun, __func__,
  156. scsi_bufflen(cmd), residual));
  157. break;
  158. }
  159. }
  160. cmd->result = DID_OK << 16 | scsi_status;
  161. if (scsi_status != SCSI_CHECK_CONDITION)
  162. break;
  163. /* Copy Sense Data into sense buffer. */
  164. qla4xxx_copy_sense(ha, sts_entry, srb);
  165. break;
  166. case SCS_INCOMPLETE:
  167. /* Always set the status to DID_ERROR, since
  168. * all conditions result in that status anyway */
  169. cmd->result = DID_ERROR << 16;
  170. break;
  171. case SCS_RESET_OCCURRED:
  172. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Device RESET occurred\n",
  173. ha->host_no, cmd->device->channel,
  174. cmd->device->id, cmd->device->lun, __func__));
  175. cmd->result = DID_RESET << 16;
  176. break;
  177. case SCS_ABORTED:
  178. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Abort occurred\n",
  179. ha->host_no, cmd->device->channel,
  180. cmd->device->id, cmd->device->lun, __func__));
  181. cmd->result = DID_RESET << 16;
  182. break;
  183. case SCS_TIMEOUT:
  184. DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: Timeout\n",
  185. ha->host_no, cmd->device->channel,
  186. cmd->device->id, cmd->device->lun));
  187. cmd->result = DID_TRANSPORT_DISRUPTED << 16;
  188. /*
  189. * Mark device missing so that we won't continue to send
  190. * I/O to this device. We should get a ddb state change
  191. * AEN soon.
  192. */
  193. if (iscsi_is_session_online(ddb_entry->sess))
  194. qla4xxx_mark_device_missing(ddb_entry->sess);
  195. break;
  196. case SCS_DATA_UNDERRUN:
  197. case SCS_DATA_OVERRUN:
  198. if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
  199. (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
  200. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: " "Data overrun\n",
  201. ha->host_no,
  202. cmd->device->channel, cmd->device->id,
  203. cmd->device->lun, __func__));
  204. cmd->result = DID_ERROR << 16;
  205. break;
  206. }
  207. scsi_set_resid(cmd, residual);
  208. if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_UNDER) {
  209. /* Both the firmware and target reported UNDERRUN:
  210. *
  211. * MID-LAYER UNDERFLOW case:
  212. * Some kernels do not properly detect midlayer
  213. * underflow, so we manually check it and return
  214. * ERROR if the minimum required data was not
  215. * received.
  216. *
  217. * ALL OTHER cases:
  218. * Fall thru to check scsi_status
  219. */
  220. if (!scsi_status && (scsi_bufflen(cmd) - residual) <
  221. cmd->underflow) {
  222. DEBUG2(ql4_printk(KERN_INFO, ha,
  223. "scsi%ld:%d:%d:%d: %s: Mid-layer Data underrun, xferlen = 0x%x,residual = 0x%x\n",
  224. ha->host_no,
  225. cmd->device->channel,
  226. cmd->device->id,
  227. cmd->device->lun, __func__,
  228. scsi_bufflen(cmd),
  229. residual));
  230. cmd->result = DID_ERROR << 16;
  231. break;
  232. }
  233. } else if (scsi_status != SAM_STAT_TASK_SET_FULL &&
  234. scsi_status != SAM_STAT_BUSY) {
  235. /*
  236. * The firmware reports UNDERRUN, but the target does
  237. * not report it:
  238. *
  239. * scsi_status | host_byte device_byte
  240. * | (19:16) (7:0)
  241. * ============= | ========= ===========
  242. * TASK_SET_FULL | DID_OK scsi_status
  243. * BUSY | DID_OK scsi_status
  244. * ALL OTHERS | DID_ERROR scsi_status
  245. *
  246. * Note: If scsi_status is task set full or busy,
  247. * then this else if would fall thru to check the
  248. * scsi_status and return DID_OK.
  249. */
  250. DEBUG2(ql4_printk(KERN_INFO, ha,
  251. "scsi%ld:%d:%d:%d: %s: Dropped frame(s) detected (0x%x of 0x%x bytes).\n",
  252. ha->host_no,
  253. cmd->device->channel,
  254. cmd->device->id,
  255. cmd->device->lun, __func__,
  256. residual,
  257. scsi_bufflen(cmd)));
  258. cmd->result = DID_ERROR << 16 | scsi_status;
  259. goto check_scsi_status;
  260. }
  261. cmd->result = DID_OK << 16 | scsi_status;
  262. check_scsi_status:
  263. if (scsi_status == SAM_STAT_CHECK_CONDITION)
  264. qla4xxx_copy_sense(ha, sts_entry, srb);
  265. break;
  266. case SCS_DEVICE_LOGGED_OUT:
  267. case SCS_DEVICE_UNAVAILABLE:
  268. DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: SCS_DEVICE "
  269. "state: 0x%x\n", ha->host_no,
  270. cmd->device->channel, cmd->device->id,
  271. cmd->device->lun, sts_entry->completionStatus));
  272. /*
  273. * Mark device missing so that we won't continue to
  274. * send I/O to this device. We should get a ddb
  275. * state change AEN soon.
  276. */
  277. if (iscsi_is_session_online(ddb_entry->sess))
  278. qla4xxx_mark_device_missing(ddb_entry->sess);
  279. cmd->result = DID_TRANSPORT_DISRUPTED << 16;
  280. break;
  281. case SCS_QUEUE_FULL:
  282. /*
  283. * SCSI Mid-Layer handles device queue full
  284. */
  285. cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
  286. DEBUG2(printk("scsi%ld:%d:%d: %s: QUEUE FULL detected "
  287. "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
  288. " iResp=%02x\n", ha->host_no, cmd->device->id,
  289. cmd->device->lun, __func__,
  290. sts_entry->completionStatus,
  291. sts_entry->scsiStatus, sts_entry->state_flags,
  292. sts_entry->iscsiFlags,
  293. sts_entry->iscsiResponse));
  294. break;
  295. default:
  296. cmd->result = DID_ERROR << 16;
  297. break;
  298. }
  299. status_entry_exit:
  300. /* complete the request, if not waiting for status_continuation pkt */
  301. srb->cc_stat = sts_entry->completionStatus;
  302. if (ha->status_srb == NULL)
  303. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  304. }
  305. /**
  306. * qla4xxx_passthru_status_entry - processes passthru status IOCBs (0x3C)
  307. * @ha: Pointer to host adapter structure.
  308. * @sts_entry: Pointer to status entry structure.
  309. **/
  310. static void qla4xxx_passthru_status_entry(struct scsi_qla_host *ha,
  311. struct passthru_status *sts_entry)
  312. {
  313. struct iscsi_task *task;
  314. struct ddb_entry *ddb_entry;
  315. struct ql4_task_data *task_data;
  316. struct iscsi_cls_conn *cls_conn;
  317. struct iscsi_conn *conn;
  318. itt_t itt;
  319. uint32_t fw_ddb_index;
  320. itt = sts_entry->handle;
  321. fw_ddb_index = le32_to_cpu(sts_entry->target);
  322. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
  323. if (ddb_entry == NULL) {
  324. ql4_printk(KERN_ERR, ha, "%s: Invalid target index = 0x%x\n",
  325. __func__, sts_entry->target);
  326. return;
  327. }
  328. cls_conn = ddb_entry->conn;
  329. conn = cls_conn->dd_data;
  330. spin_lock(&conn->session->lock);
  331. task = iscsi_itt_to_task(conn, itt);
  332. spin_unlock(&conn->session->lock);
  333. if (task == NULL) {
  334. ql4_printk(KERN_ERR, ha, "%s: Task is NULL\n", __func__);
  335. return;
  336. }
  337. task_data = task->dd_data;
  338. memcpy(&task_data->sts, sts_entry, sizeof(struct passthru_status));
  339. ha->iocb_cnt -= task_data->iocb_req_cnt;
  340. queue_work(ha->task_wq, &task_data->task_work);
  341. }
  342. static struct mrb *qla4xxx_del_mrb_from_active_array(struct scsi_qla_host *ha,
  343. uint32_t index)
  344. {
  345. struct mrb *mrb = NULL;
  346. /* validate handle and remove from active array */
  347. if (index >= MAX_MRB)
  348. return mrb;
  349. mrb = ha->active_mrb_array[index];
  350. ha->active_mrb_array[index] = NULL;
  351. if (!mrb)
  352. return mrb;
  353. /* update counters */
  354. ha->iocb_cnt -= mrb->iocb_cnt;
  355. return mrb;
  356. }
  357. static void qla4xxx_mbox_status_entry(struct scsi_qla_host *ha,
  358. struct mbox_status_iocb *mbox_sts_entry)
  359. {
  360. struct mrb *mrb;
  361. uint32_t status;
  362. uint32_t data_size;
  363. mrb = qla4xxx_del_mrb_from_active_array(ha,
  364. le32_to_cpu(mbox_sts_entry->handle));
  365. if (mrb == NULL) {
  366. ql4_printk(KERN_WARNING, ha, "%s: mrb[%d] is null\n", __func__,
  367. mbox_sts_entry->handle);
  368. return;
  369. }
  370. switch (mrb->mbox_cmd) {
  371. case MBOX_CMD_PING:
  372. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: mbox_cmd = 0x%x, "
  373. "mbox_sts[0] = 0x%x, mbox_sts[6] = 0x%x\n",
  374. __func__, mrb->mbox_cmd,
  375. mbox_sts_entry->out_mbox[0],
  376. mbox_sts_entry->out_mbox[6]));
  377. if (mbox_sts_entry->out_mbox[0] == MBOX_STS_COMMAND_COMPLETE)
  378. status = ISCSI_PING_SUCCESS;
  379. else
  380. status = mbox_sts_entry->out_mbox[6];
  381. data_size = sizeof(mbox_sts_entry->out_mbox);
  382. qla4xxx_post_ping_evt_work(ha, status, mrb->pid, data_size,
  383. (uint8_t *) mbox_sts_entry->out_mbox);
  384. break;
  385. default:
  386. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: invalid mbox_cmd = "
  387. "0x%x\n", __func__, mrb->mbox_cmd));
  388. }
  389. kfree(mrb);
  390. return;
  391. }
  392. /**
  393. * qla4xxx_process_response_queue - process response queue completions
  394. * @ha: Pointer to host adapter structure.
  395. *
  396. * This routine process response queue completions in interrupt context.
  397. * Hardware_lock locked upon entry
  398. **/
  399. void qla4xxx_process_response_queue(struct scsi_qla_host *ha)
  400. {
  401. uint32_t count = 0;
  402. struct srb *srb = NULL;
  403. struct status_entry *sts_entry;
  404. /* Process all responses from response queue */
  405. while ((ha->response_ptr->signature != RESPONSE_PROCESSED)) {
  406. sts_entry = (struct status_entry *) ha->response_ptr;
  407. count++;
  408. /* Advance pointers for next entry */
  409. if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
  410. ha->response_out = 0;
  411. ha->response_ptr = ha->response_ring;
  412. } else {
  413. ha->response_out++;
  414. ha->response_ptr++;
  415. }
  416. /* process entry */
  417. switch (sts_entry->hdr.entryType) {
  418. case ET_STATUS:
  419. /* Common status */
  420. qla4xxx_status_entry(ha, sts_entry);
  421. break;
  422. case ET_PASSTHRU_STATUS:
  423. if (sts_entry->hdr.systemDefined == SD_ISCSI_PDU)
  424. qla4xxx_passthru_status_entry(ha,
  425. (struct passthru_status *)sts_entry);
  426. else
  427. ql4_printk(KERN_ERR, ha,
  428. "%s: Invalid status received\n",
  429. __func__);
  430. break;
  431. case ET_STATUS_CONTINUATION:
  432. qla4xxx_status_cont_entry(ha,
  433. (struct status_cont_entry *) sts_entry);
  434. break;
  435. case ET_COMMAND:
  436. /* ISP device queue is full. Command not
  437. * accepted by ISP. Queue command for
  438. * later */
  439. srb = qla4xxx_del_from_active_array(ha,
  440. le32_to_cpu(sts_entry->
  441. handle));
  442. if (srb == NULL)
  443. goto exit_prq_invalid_handle;
  444. DEBUG2(printk("scsi%ld: %s: FW device queue full, "
  445. "srb %p\n", ha->host_no, __func__, srb));
  446. /* ETRY normally by sending it back with
  447. * DID_BUS_BUSY */
  448. srb->cmd->result = DID_BUS_BUSY << 16;
  449. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  450. break;
  451. case ET_CONTINUE:
  452. /* Just throw away the continuation entries */
  453. DEBUG2(printk("scsi%ld: %s: Continuation entry - "
  454. "ignoring\n", ha->host_no, __func__));
  455. break;
  456. case ET_MBOX_STATUS:
  457. DEBUG2(ql4_printk(KERN_INFO, ha,
  458. "%s: mbox status IOCB\n", __func__));
  459. qla4xxx_mbox_status_entry(ha,
  460. (struct mbox_status_iocb *)sts_entry);
  461. break;
  462. default:
  463. /*
  464. * Invalid entry in response queue, reset RISC
  465. * firmware.
  466. */
  467. DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
  468. "response queue \n", ha->host_no,
  469. __func__,
  470. sts_entry->hdr.entryType));
  471. goto exit_prq_error;
  472. }
  473. ((struct response *)sts_entry)->signature = RESPONSE_PROCESSED;
  474. wmb();
  475. }
  476. /*
  477. * Tell ISP we're done with response(s). This also clears the interrupt.
  478. */
  479. ha->isp_ops->complete_iocb(ha);
  480. return;
  481. exit_prq_invalid_handle:
  482. DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
  483. ha->host_no, __func__, srb, sts_entry->hdr.entryType,
  484. sts_entry->completionStatus));
  485. exit_prq_error:
  486. ha->isp_ops->complete_iocb(ha);
  487. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  488. }
  489. /**
  490. * qla4_83xx_loopback_in_progress: Is loopback in progress?
  491. * @ha: Pointer to host adapter structure.
  492. * @ret: 1 = loopback in progress, 0 = loopback not in progress
  493. **/
  494. static int qla4_83xx_loopback_in_progress(struct scsi_qla_host *ha)
  495. {
  496. int rval = 1;
  497. if (is_qla8032(ha) || is_qla8042(ha)) {
  498. if ((ha->idc_info.info2 & ENABLE_INTERNAL_LOOPBACK) ||
  499. (ha->idc_info.info2 & ENABLE_EXTERNAL_LOOPBACK)) {
  500. DEBUG2(ql4_printk(KERN_INFO, ha,
  501. "%s: Loopback diagnostics in progress\n",
  502. __func__));
  503. rval = 1;
  504. } else {
  505. DEBUG2(ql4_printk(KERN_INFO, ha,
  506. "%s: Loopback diagnostics not in progress\n",
  507. __func__));
  508. rval = 0;
  509. }
  510. }
  511. return rval;
  512. }
  513. /**
  514. * qla4xxx_isr_decode_mailbox - decodes mailbox status
  515. * @ha: Pointer to host adapter structure.
  516. * @mailbox_status: Mailbox status.
  517. *
  518. * This routine decodes the mailbox status during the ISR.
  519. * Hardware_lock locked upon entry. runs in interrupt context.
  520. **/
  521. static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
  522. uint32_t mbox_status)
  523. {
  524. int i;
  525. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  526. __le32 __iomem *mailbox_out;
  527. if (is_qla8032(ha) || is_qla8042(ha))
  528. mailbox_out = &ha->qla4_83xx_reg->mailbox_out[0];
  529. else if (is_qla8022(ha))
  530. mailbox_out = &ha->qla4_82xx_reg->mailbox_out[0];
  531. else
  532. mailbox_out = &ha->reg->mailbox[0];
  533. if ((mbox_status == MBOX_STS_BUSY) ||
  534. (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
  535. (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
  536. ha->mbox_status[0] = mbox_status;
  537. if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
  538. /*
  539. * Copy all mailbox registers to a temporary
  540. * location and set mailbox command done flag
  541. */
  542. for (i = 0; i < ha->mbox_status_count; i++)
  543. ha->mbox_status[i] = readl(&mailbox_out[i]);
  544. set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  545. if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags))
  546. complete(&ha->mbx_intr_comp);
  547. }
  548. } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
  549. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  550. mbox_sts[i] = readl(&mailbox_out[i]);
  551. /* Immediately process the AENs that don't require much work.
  552. * Only queue the database_changed AENs */
  553. if (ha->aen_log.count < MAX_AEN_ENTRIES) {
  554. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  555. ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
  556. mbox_sts[i];
  557. ha->aen_log.count++;
  558. }
  559. switch (mbox_status) {
  560. case MBOX_ASTS_SYSTEM_ERROR:
  561. /* Log Mailbox registers */
  562. ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
  563. qla4xxx_dump_registers(ha);
  564. if ((is_qla8022(ha) && ql4xdontresethba) ||
  565. ((is_qla8032(ha) || is_qla8042(ha)) &&
  566. qla4_83xx_idc_dontreset(ha))) {
  567. DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
  568. ha->host_no, __func__));
  569. } else {
  570. set_bit(AF_GET_CRASH_RECORD, &ha->flags);
  571. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  572. }
  573. break;
  574. case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
  575. case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
  576. case MBOX_ASTS_NVRAM_INVALID:
  577. case MBOX_ASTS_IP_ADDRESS_CHANGED:
  578. case MBOX_ASTS_DHCP_LEASE_EXPIRED:
  579. DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
  580. "Reset HA\n", ha->host_no, mbox_status));
  581. if (is_qla80XX(ha))
  582. set_bit(DPC_RESET_HA_FW_CONTEXT,
  583. &ha->dpc_flags);
  584. else
  585. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  586. break;
  587. case MBOX_ASTS_LINK_UP:
  588. set_bit(AF_LINK_UP, &ha->flags);
  589. if (test_bit(AF_INIT_DONE, &ha->flags))
  590. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  591. ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
  592. qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKUP,
  593. sizeof(mbox_sts),
  594. (uint8_t *) mbox_sts);
  595. break;
  596. case MBOX_ASTS_LINK_DOWN:
  597. clear_bit(AF_LINK_UP, &ha->flags);
  598. if (test_bit(AF_INIT_DONE, &ha->flags)) {
  599. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  600. qla4xxx_wake_dpc(ha);
  601. }
  602. ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
  603. qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKDOWN,
  604. sizeof(mbox_sts),
  605. (uint8_t *) mbox_sts);
  606. break;
  607. case MBOX_ASTS_HEARTBEAT:
  608. ha->seconds_since_last_heartbeat = 0;
  609. break;
  610. case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
  611. DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
  612. "ACQUIRED\n", ha->host_no, mbox_status));
  613. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  614. break;
  615. case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
  616. case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
  617. * mode
  618. * only */
  619. case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
  620. case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
  621. case MBOX_ASTS_SUBNET_STATE_CHANGE:
  622. case MBOX_ASTS_DUPLICATE_IP:
  623. /* No action */
  624. DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
  625. mbox_status));
  626. break;
  627. case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
  628. printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
  629. "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
  630. mbox_sts[2], mbox_sts[3]);
  631. /* mbox_sts[2] = Old ACB state
  632. * mbox_sts[3] = new ACB state */
  633. if ((mbox_sts[3] == ACB_STATE_VALID) &&
  634. ((mbox_sts[2] == ACB_STATE_TENTATIVE) ||
  635. (mbox_sts[2] == ACB_STATE_ACQUIRING))) {
  636. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  637. } else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
  638. (mbox_sts[2] == ACB_STATE_VALID)) {
  639. if (is_qla80XX(ha))
  640. set_bit(DPC_RESET_HA_FW_CONTEXT,
  641. &ha->dpc_flags);
  642. else
  643. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  644. } else if (mbox_sts[3] == ACB_STATE_DISABLING) {
  645. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ACB in disabling state\n",
  646. ha->host_no, __func__);
  647. } else if ((mbox_sts[3] == ACB_STATE_UNCONFIGURED)) {
  648. complete(&ha->disable_acb_comp);
  649. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ACB state unconfigured\n",
  650. ha->host_no, __func__);
  651. }
  652. break;
  653. case MBOX_ASTS_MAC_ADDRESS_CHANGED:
  654. case MBOX_ASTS_DNS:
  655. /* No action */
  656. DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
  657. "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
  658. ha->host_no, mbox_sts[0],
  659. mbox_sts[1], mbox_sts[2]));
  660. break;
  661. case MBOX_ASTS_SELF_TEST_FAILED:
  662. case MBOX_ASTS_LOGIN_FAILED:
  663. /* No action */
  664. DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
  665. "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
  666. ha->host_no, mbox_sts[0], mbox_sts[1],
  667. mbox_sts[2], mbox_sts[3]));
  668. break;
  669. case MBOX_ASTS_DATABASE_CHANGED:
  670. /* Queue AEN information and process it in the DPC
  671. * routine */
  672. if (ha->aen_q_count > 0) {
  673. /* decrement available counter */
  674. ha->aen_q_count--;
  675. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  676. ha->aen_q[ha->aen_in].mbox_sts[i] =
  677. mbox_sts[i];
  678. /* print debug message */
  679. DEBUG2(printk("scsi%ld: AEN[%d] %04x queued "
  680. "mb1:0x%x mb2:0x%x mb3:0x%x "
  681. "mb4:0x%x mb5:0x%x\n",
  682. ha->host_no, ha->aen_in,
  683. mbox_sts[0], mbox_sts[1],
  684. mbox_sts[2], mbox_sts[3],
  685. mbox_sts[4], mbox_sts[5]));
  686. /* advance pointer */
  687. ha->aen_in++;
  688. if (ha->aen_in == MAX_AEN_ENTRIES)
  689. ha->aen_in = 0;
  690. /* The DPC routine will process the aen */
  691. set_bit(DPC_AEN, &ha->dpc_flags);
  692. } else {
  693. DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
  694. "overflowed! AEN LOST!!\n",
  695. ha->host_no, __func__,
  696. mbox_sts[0]));
  697. DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
  698. ha->host_no));
  699. for (i = 0; i < MAX_AEN_ENTRIES; i++) {
  700. DEBUG2(printk("AEN[%d] %04x %04x %04x "
  701. "%04x\n", i, mbox_sts[0],
  702. mbox_sts[1], mbox_sts[2],
  703. mbox_sts[3]));
  704. }
  705. }
  706. break;
  707. case MBOX_ASTS_TXSCVR_INSERTED:
  708. DEBUG2(printk(KERN_WARNING
  709. "scsi%ld: AEN %04x Transceiver"
  710. " inserted\n", ha->host_no, mbox_sts[0]));
  711. break;
  712. case MBOX_ASTS_TXSCVR_REMOVED:
  713. DEBUG2(printk(KERN_WARNING
  714. "scsi%ld: AEN %04x Transceiver"
  715. " removed\n", ha->host_no, mbox_sts[0]));
  716. break;
  717. case MBOX_ASTS_IDC_REQUEST_NOTIFICATION:
  718. {
  719. uint32_t opcode;
  720. if (is_qla8032(ha) || is_qla8042(ha)) {
  721. DEBUG2(ql4_printk(KERN_INFO, ha,
  722. "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
  723. ha->host_no, mbox_sts[0],
  724. mbox_sts[1], mbox_sts[2],
  725. mbox_sts[3], mbox_sts[4]));
  726. opcode = mbox_sts[1] >> 16;
  727. if ((opcode == MBOX_CMD_SET_PORT_CONFIG) ||
  728. (opcode == MBOX_CMD_PORT_RESET)) {
  729. set_bit(DPC_POST_IDC_ACK,
  730. &ha->dpc_flags);
  731. ha->idc_info.request_desc = mbox_sts[1];
  732. ha->idc_info.info1 = mbox_sts[2];
  733. ha->idc_info.info2 = mbox_sts[3];
  734. ha->idc_info.info3 = mbox_sts[4];
  735. qla4xxx_wake_dpc(ha);
  736. }
  737. }
  738. break;
  739. }
  740. case MBOX_ASTS_IDC_COMPLETE:
  741. if (is_qla8032(ha) || is_qla8042(ha)) {
  742. DEBUG2(ql4_printk(KERN_INFO, ha,
  743. "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
  744. ha->host_no, mbox_sts[0],
  745. mbox_sts[1], mbox_sts[2],
  746. mbox_sts[3], mbox_sts[4]));
  747. DEBUG2(ql4_printk(KERN_INFO, ha,
  748. "scsi:%ld: AEN %04x IDC Complete notification\n",
  749. ha->host_no, mbox_sts[0]));
  750. if (qla4_83xx_loopback_in_progress(ha)) {
  751. set_bit(AF_LOOPBACK, &ha->flags);
  752. } else {
  753. clear_bit(AF_LOOPBACK, &ha->flags);
  754. if (ha->saved_acb)
  755. set_bit(DPC_RESTORE_ACB,
  756. &ha->dpc_flags);
  757. }
  758. qla4xxx_wake_dpc(ha);
  759. }
  760. break;
  761. case MBOX_ASTS_IPV6_DEFAULT_ROUTER_CHANGED:
  762. DEBUG2(ql4_printk(KERN_INFO, ha,
  763. "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
  764. ha->host_no, mbox_sts[0], mbox_sts[1],
  765. mbox_sts[2], mbox_sts[3], mbox_sts[4],
  766. mbox_sts[5]));
  767. DEBUG2(ql4_printk(KERN_INFO, ha,
  768. "scsi%ld: AEN %04x Received IPv6 default router changed notification\n",
  769. ha->host_no, mbox_sts[0]));
  770. break;
  771. case MBOX_ASTS_IDC_TIME_EXTEND_NOTIFICATION:
  772. DEBUG2(ql4_printk(KERN_INFO, ha,
  773. "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
  774. ha->host_no, mbox_sts[0], mbox_sts[1],
  775. mbox_sts[2], mbox_sts[3], mbox_sts[4],
  776. mbox_sts[5]));
  777. DEBUG2(ql4_printk(KERN_INFO, ha,
  778. "scsi%ld: AEN %04x Received IDC Extend Timeout notification\n",
  779. ha->host_no, mbox_sts[0]));
  780. break;
  781. case MBOX_ASTS_INITIALIZATION_FAILED:
  782. DEBUG2(ql4_printk(KERN_INFO, ha,
  783. "scsi%ld: AEN %04x, mbox_sts[3]=%08x\n",
  784. ha->host_no, mbox_sts[0],
  785. mbox_sts[3]));
  786. break;
  787. case MBOX_ASTS_SYSTEM_WARNING_EVENT:
  788. DEBUG2(ql4_printk(KERN_WARNING, ha,
  789. "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
  790. ha->host_no, mbox_sts[0], mbox_sts[1],
  791. mbox_sts[2], mbox_sts[3], mbox_sts[4],
  792. mbox_sts[5]));
  793. break;
  794. case MBOX_ASTS_DCBX_CONF_CHANGE:
  795. DEBUG2(ql4_printk(KERN_INFO, ha,
  796. "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
  797. ha->host_no, mbox_sts[0], mbox_sts[1],
  798. mbox_sts[2], mbox_sts[3], mbox_sts[4],
  799. mbox_sts[5]));
  800. DEBUG2(ql4_printk(KERN_INFO, ha,
  801. "scsi%ld: AEN %04x Received DCBX configuration changed notification\n",
  802. ha->host_no, mbox_sts[0]));
  803. break;
  804. default:
  805. DEBUG2(printk(KERN_WARNING
  806. "scsi%ld: AEN %04x UNKNOWN\n",
  807. ha->host_no, mbox_sts[0]));
  808. break;
  809. }
  810. } else {
  811. DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
  812. ha->host_no, mbox_status));
  813. ha->mbox_status[0] = mbox_status;
  814. }
  815. }
  816. void qla4_83xx_interrupt_service_routine(struct scsi_qla_host *ha,
  817. uint32_t intr_status)
  818. {
  819. /* Process mailbox/asynch event interrupt.*/
  820. if (intr_status) {
  821. qla4xxx_isr_decode_mailbox(ha,
  822. readl(&ha->qla4_83xx_reg->mailbox_out[0]));
  823. /* clear the interrupt */
  824. writel(0, &ha->qla4_83xx_reg->risc_intr);
  825. } else {
  826. qla4xxx_process_response_queue(ha);
  827. }
  828. /* clear the interrupt */
  829. writel(0, &ha->qla4_83xx_reg->mb_int_mask);
  830. }
  831. /**
  832. * qla4_82xx_interrupt_service_routine - isr
  833. * @ha: pointer to host adapter structure.
  834. *
  835. * This is the main interrupt service routine.
  836. * hardware_lock locked upon entry. runs in interrupt context.
  837. **/
  838. void qla4_82xx_interrupt_service_routine(struct scsi_qla_host *ha,
  839. uint32_t intr_status)
  840. {
  841. /* Process response queue interrupt. */
  842. if (intr_status & HSRX_RISC_IOCB_INT)
  843. qla4xxx_process_response_queue(ha);
  844. /* Process mailbox/asynch event interrupt.*/
  845. if (intr_status & HSRX_RISC_MB_INT)
  846. qla4xxx_isr_decode_mailbox(ha,
  847. readl(&ha->qla4_82xx_reg->mailbox_out[0]));
  848. /* clear the interrupt */
  849. writel(0, &ha->qla4_82xx_reg->host_int);
  850. readl(&ha->qla4_82xx_reg->host_int);
  851. }
  852. /**
  853. * qla4xxx_interrupt_service_routine - isr
  854. * @ha: pointer to host adapter structure.
  855. *
  856. * This is the main interrupt service routine.
  857. * hardware_lock locked upon entry. runs in interrupt context.
  858. **/
  859. void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
  860. uint32_t intr_status)
  861. {
  862. /* Process response queue interrupt. */
  863. if (intr_status & CSR_SCSI_COMPLETION_INTR)
  864. qla4xxx_process_response_queue(ha);
  865. /* Process mailbox/asynch event interrupt.*/
  866. if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
  867. qla4xxx_isr_decode_mailbox(ha,
  868. readl(&ha->reg->mailbox[0]));
  869. /* Clear Mailbox Interrupt */
  870. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  871. &ha->reg->ctrl_status);
  872. readl(&ha->reg->ctrl_status);
  873. }
  874. }
  875. /**
  876. * qla4_82xx_spurious_interrupt - processes spurious interrupt
  877. * @ha: pointer to host adapter structure.
  878. * @reqs_count: .
  879. *
  880. **/
  881. static void qla4_82xx_spurious_interrupt(struct scsi_qla_host *ha,
  882. uint8_t reqs_count)
  883. {
  884. if (reqs_count)
  885. return;
  886. DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
  887. if (is_qla8022(ha)) {
  888. writel(0, &ha->qla4_82xx_reg->host_int);
  889. if (test_bit(AF_INTx_ENABLED, &ha->flags))
  890. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
  891. 0xfbff);
  892. }
  893. ha->spurious_int_count++;
  894. }
  895. /**
  896. * qla4xxx_intr_handler - hardware interrupt handler.
  897. * @irq: Unused
  898. * @dev_id: Pointer to host adapter structure
  899. **/
  900. irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
  901. {
  902. struct scsi_qla_host *ha;
  903. uint32_t intr_status;
  904. unsigned long flags = 0;
  905. uint8_t reqs_count = 0;
  906. ha = (struct scsi_qla_host *) dev_id;
  907. if (!ha) {
  908. DEBUG2(printk(KERN_INFO
  909. "qla4xxx: Interrupt with NULL host ptr\n"));
  910. return IRQ_NONE;
  911. }
  912. spin_lock_irqsave(&ha->hardware_lock, flags);
  913. ha->isr_count++;
  914. /*
  915. * Repeatedly service interrupts up to a maximum of
  916. * MAX_REQS_SERVICED_PER_INTR
  917. */
  918. while (1) {
  919. /*
  920. * Read interrupt status
  921. */
  922. if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
  923. ha->response_out)
  924. intr_status = CSR_SCSI_COMPLETION_INTR;
  925. else
  926. intr_status = readl(&ha->reg->ctrl_status);
  927. if ((intr_status &
  928. (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
  929. if (reqs_count == 0)
  930. ha->spurious_int_count++;
  931. break;
  932. }
  933. if (intr_status & CSR_FATAL_ERROR) {
  934. DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
  935. "Status 0x%04x\n", ha->host_no,
  936. readl(isp_port_error_status (ha))));
  937. /* Issue Soft Reset to clear this error condition.
  938. * This will prevent the RISC from repeatedly
  939. * interrupting the driver; thus, allowing the DPC to
  940. * get scheduled to continue error recovery.
  941. * NOTE: Disabling RISC interrupts does not work in
  942. * this case, as CSR_FATAL_ERROR overrides
  943. * CSR_SCSI_INTR_ENABLE */
  944. if ((readl(&ha->reg->ctrl_status) &
  945. CSR_SCSI_RESET_INTR) == 0) {
  946. writel(set_rmask(CSR_SOFT_RESET),
  947. &ha->reg->ctrl_status);
  948. readl(&ha->reg->ctrl_status);
  949. }
  950. writel(set_rmask(CSR_FATAL_ERROR),
  951. &ha->reg->ctrl_status);
  952. readl(&ha->reg->ctrl_status);
  953. __qla4xxx_disable_intrs(ha);
  954. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  955. break;
  956. } else if (intr_status & CSR_SCSI_RESET_INTR) {
  957. clear_bit(AF_ONLINE, &ha->flags);
  958. __qla4xxx_disable_intrs(ha);
  959. writel(set_rmask(CSR_SCSI_RESET_INTR),
  960. &ha->reg->ctrl_status);
  961. readl(&ha->reg->ctrl_status);
  962. if (!test_bit(AF_HA_REMOVAL, &ha->flags))
  963. set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  964. break;
  965. } else if (intr_status & INTR_PENDING) {
  966. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  967. ha->total_io_count++;
  968. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  969. break;
  970. }
  971. }
  972. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  973. return IRQ_HANDLED;
  974. }
  975. /**
  976. * qla4_82xx_intr_handler - hardware interrupt handler.
  977. * @irq: Unused
  978. * @dev_id: Pointer to host adapter structure
  979. **/
  980. irqreturn_t qla4_82xx_intr_handler(int irq, void *dev_id)
  981. {
  982. struct scsi_qla_host *ha = dev_id;
  983. uint32_t intr_status;
  984. uint32_t status;
  985. unsigned long flags = 0;
  986. uint8_t reqs_count = 0;
  987. if (unlikely(pci_channel_offline(ha->pdev)))
  988. return IRQ_HANDLED;
  989. ha->isr_count++;
  990. status = qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  991. if (!(status & ha->nx_legacy_intr.int_vec_bit))
  992. return IRQ_NONE;
  993. status = qla4_82xx_rd_32(ha, ISR_INT_STATE_REG);
  994. if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
  995. DEBUG7(ql4_printk(KERN_INFO, ha,
  996. "%s legacy Int not triggered\n", __func__));
  997. return IRQ_NONE;
  998. }
  999. /* clear the interrupt */
  1000. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  1001. /* read twice to ensure write is flushed */
  1002. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  1003. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  1004. spin_lock_irqsave(&ha->hardware_lock, flags);
  1005. while (1) {
  1006. if (!(readl(&ha->qla4_82xx_reg->host_int) &
  1007. ISRX_82XX_RISC_INT)) {
  1008. qla4_82xx_spurious_interrupt(ha, reqs_count);
  1009. break;
  1010. }
  1011. intr_status = readl(&ha->qla4_82xx_reg->host_status);
  1012. if ((intr_status &
  1013. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  1014. qla4_82xx_spurious_interrupt(ha, reqs_count);
  1015. break;
  1016. }
  1017. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  1018. /* Enable Interrupt */
  1019. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
  1020. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  1021. break;
  1022. }
  1023. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1024. return IRQ_HANDLED;
  1025. }
  1026. #define LEG_INT_PTR_B31 (1 << 31)
  1027. #define LEG_INT_PTR_B30 (1 << 30)
  1028. #define PF_BITS_MASK (0xF << 16)
  1029. /**
  1030. * qla4_83xx_intr_handler - hardware interrupt handler.
  1031. * @irq: Unused
  1032. * @dev_id: Pointer to host adapter structure
  1033. **/
  1034. irqreturn_t qla4_83xx_intr_handler(int irq, void *dev_id)
  1035. {
  1036. struct scsi_qla_host *ha = dev_id;
  1037. uint32_t leg_int_ptr = 0;
  1038. unsigned long flags = 0;
  1039. ha->isr_count++;
  1040. leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
  1041. /* Legacy interrupt is valid if bit31 of leg_int_ptr is set */
  1042. if (!(leg_int_ptr & LEG_INT_PTR_B31)) {
  1043. DEBUG7(ql4_printk(KERN_ERR, ha,
  1044. "%s: Legacy Interrupt Bit 31 not set, spurious interrupt!\n",
  1045. __func__));
  1046. return IRQ_NONE;
  1047. }
  1048. /* Validate the PCIE function ID set in leg_int_ptr bits [19..16] */
  1049. if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit) {
  1050. DEBUG7(ql4_printk(KERN_ERR, ha,
  1051. "%s: Incorrect function ID 0x%x in legacy interrupt register, ha->pf_bit = 0x%x\n",
  1052. __func__, (leg_int_ptr & PF_BITS_MASK),
  1053. ha->pf_bit));
  1054. return IRQ_NONE;
  1055. }
  1056. /* To de-assert legacy interrupt, write 0 to Legacy Interrupt Trigger
  1057. * Control register and poll till Legacy Interrupt Pointer register
  1058. * bit30 is 0.
  1059. */
  1060. writel(0, &ha->qla4_83xx_reg->leg_int_trig);
  1061. do {
  1062. leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
  1063. if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit)
  1064. break;
  1065. } while (leg_int_ptr & LEG_INT_PTR_B30);
  1066. spin_lock_irqsave(&ha->hardware_lock, flags);
  1067. leg_int_ptr = readl(&ha->qla4_83xx_reg->risc_intr);
  1068. ha->isp_ops->interrupt_service_routine(ha, leg_int_ptr);
  1069. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1070. return IRQ_HANDLED;
  1071. }
  1072. irqreturn_t
  1073. qla4_8xxx_msi_handler(int irq, void *dev_id)
  1074. {
  1075. struct scsi_qla_host *ha;
  1076. ha = (struct scsi_qla_host *) dev_id;
  1077. if (!ha) {
  1078. DEBUG2(printk(KERN_INFO
  1079. "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
  1080. return IRQ_NONE;
  1081. }
  1082. ha->isr_count++;
  1083. /* clear the interrupt */
  1084. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  1085. /* read twice to ensure write is flushed */
  1086. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  1087. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  1088. return qla4_8xxx_default_intr_handler(irq, dev_id);
  1089. }
  1090. static irqreturn_t qla4_83xx_mailbox_intr_handler(int irq, void *dev_id)
  1091. {
  1092. struct scsi_qla_host *ha = dev_id;
  1093. unsigned long flags;
  1094. uint32_t ival = 0;
  1095. spin_lock_irqsave(&ha->hardware_lock, flags);
  1096. ival = readl(&ha->qla4_83xx_reg->risc_intr);
  1097. if (ival == 0) {
  1098. ql4_printk(KERN_INFO, ha,
  1099. "%s: It is a spurious mailbox interrupt!\n",
  1100. __func__);
  1101. ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
  1102. ival &= ~INT_MASK_FW_MB;
  1103. writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
  1104. goto exit;
  1105. }
  1106. qla4xxx_isr_decode_mailbox(ha,
  1107. readl(&ha->qla4_83xx_reg->mailbox_out[0]));
  1108. writel(0, &ha->qla4_83xx_reg->risc_intr);
  1109. ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
  1110. ival &= ~INT_MASK_FW_MB;
  1111. writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
  1112. ha->isr_count++;
  1113. exit:
  1114. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1115. return IRQ_HANDLED;
  1116. }
  1117. /**
  1118. * qla4_8xxx_default_intr_handler - hardware interrupt handler.
  1119. * @irq: Unused
  1120. * @dev_id: Pointer to host adapter structure
  1121. *
  1122. * This interrupt handler is called directly for MSI-X, and
  1123. * called indirectly for MSI.
  1124. **/
  1125. irqreturn_t
  1126. qla4_8xxx_default_intr_handler(int irq, void *dev_id)
  1127. {
  1128. struct scsi_qla_host *ha = dev_id;
  1129. unsigned long flags;
  1130. uint32_t intr_status;
  1131. uint8_t reqs_count = 0;
  1132. if (is_qla8032(ha) || is_qla8042(ha)) {
  1133. qla4_83xx_mailbox_intr_handler(irq, dev_id);
  1134. } else {
  1135. spin_lock_irqsave(&ha->hardware_lock, flags);
  1136. while (1) {
  1137. if (!(readl(&ha->qla4_82xx_reg->host_int) &
  1138. ISRX_82XX_RISC_INT)) {
  1139. qla4_82xx_spurious_interrupt(ha, reqs_count);
  1140. break;
  1141. }
  1142. intr_status = readl(&ha->qla4_82xx_reg->host_status);
  1143. if ((intr_status &
  1144. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  1145. qla4_82xx_spurious_interrupt(ha, reqs_count);
  1146. break;
  1147. }
  1148. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  1149. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  1150. break;
  1151. }
  1152. ha->isr_count++;
  1153. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1154. }
  1155. return IRQ_HANDLED;
  1156. }
  1157. irqreturn_t
  1158. qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
  1159. {
  1160. struct scsi_qla_host *ha = dev_id;
  1161. unsigned long flags;
  1162. uint32_t ival = 0;
  1163. spin_lock_irqsave(&ha->hardware_lock, flags);
  1164. if (is_qla8032(ha) || is_qla8042(ha)) {
  1165. ival = readl(&ha->qla4_83xx_reg->iocb_int_mask);
  1166. if (ival == 0) {
  1167. ql4_printk(KERN_INFO, ha, "%s: It is a spurious iocb interrupt!\n",
  1168. __func__);
  1169. goto exit_msix_rsp_q;
  1170. }
  1171. qla4xxx_process_response_queue(ha);
  1172. writel(0, &ha->qla4_83xx_reg->iocb_int_mask);
  1173. } else {
  1174. qla4xxx_process_response_queue(ha);
  1175. writel(0, &ha->qla4_82xx_reg->host_int);
  1176. }
  1177. ha->isr_count++;
  1178. exit_msix_rsp_q:
  1179. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1180. return IRQ_HANDLED;
  1181. }
  1182. /**
  1183. * qla4xxx_process_aen - processes AENs generated by firmware
  1184. * @ha: pointer to host adapter structure.
  1185. * @process_aen: type of AENs to process
  1186. *
  1187. * Processes specific types of Asynchronous Events generated by firmware.
  1188. * The type of AENs to process is specified by process_aen and can be
  1189. * PROCESS_ALL_AENS 0
  1190. * FLUSH_DDB_CHANGED_AENS 1
  1191. * RELOGIN_DDB_CHANGED_AENS 2
  1192. **/
  1193. void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
  1194. {
  1195. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  1196. struct aen *aen;
  1197. int i;
  1198. unsigned long flags;
  1199. spin_lock_irqsave(&ha->hardware_lock, flags);
  1200. while (ha->aen_out != ha->aen_in) {
  1201. aen = &ha->aen_q[ha->aen_out];
  1202. /* copy aen information to local structure */
  1203. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  1204. mbox_sts[i] = aen->mbox_sts[i];
  1205. ha->aen_q_count++;
  1206. ha->aen_out++;
  1207. if (ha->aen_out == MAX_AEN_ENTRIES)
  1208. ha->aen_out = 0;
  1209. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1210. DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
  1211. " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
  1212. (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
  1213. mbox_sts[0], mbox_sts[1], mbox_sts[2],
  1214. mbox_sts[3], mbox_sts[4]));
  1215. switch (mbox_sts[0]) {
  1216. case MBOX_ASTS_DATABASE_CHANGED:
  1217. switch (process_aen) {
  1218. case FLUSH_DDB_CHANGED_AENS:
  1219. DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
  1220. "[%d] state=%04x FLUSHED!\n",
  1221. ha->host_no, ha->aen_out,
  1222. mbox_sts[0], mbox_sts[2],
  1223. mbox_sts[3]));
  1224. break;
  1225. case PROCESS_ALL_AENS:
  1226. default:
  1227. /* Specific device. */
  1228. if (mbox_sts[1] == 1)
  1229. qla4xxx_process_ddb_changed(ha,
  1230. mbox_sts[2], mbox_sts[3],
  1231. mbox_sts[4]);
  1232. break;
  1233. }
  1234. }
  1235. spin_lock_irqsave(&ha->hardware_lock, flags);
  1236. }
  1237. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1238. }
  1239. int qla4xxx_request_irqs(struct scsi_qla_host *ha)
  1240. {
  1241. int ret;
  1242. if (is_qla40XX(ha))
  1243. goto try_intx;
  1244. if (ql4xenablemsix == 2) {
  1245. /* Note: MSI Interrupts not supported for ISP8324 and ISP8042 */
  1246. if (is_qla8032(ha) || is_qla8042(ha)) {
  1247. ql4_printk(KERN_INFO, ha, "%s: MSI Interrupts not supported for ISP%04x, Falling back-to INTx mode\n",
  1248. __func__, ha->pdev->device);
  1249. goto try_intx;
  1250. }
  1251. goto try_msi;
  1252. }
  1253. if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
  1254. goto try_intx;
  1255. /* Trying MSI-X */
  1256. ret = qla4_8xxx_enable_msix(ha);
  1257. if (!ret) {
  1258. DEBUG2(ql4_printk(KERN_INFO, ha,
  1259. "MSI-X: Enabled (0x%X).\n", ha->revision_id));
  1260. goto irq_attached;
  1261. } else {
  1262. if (is_qla8032(ha) || is_qla8042(ha)) {
  1263. ql4_printk(KERN_INFO, ha, "%s: ISP%04x: MSI-X: Falling back-to INTx mode. ret = %d\n",
  1264. __func__, ha->pdev->device, ret);
  1265. goto try_intx;
  1266. }
  1267. }
  1268. ql4_printk(KERN_WARNING, ha,
  1269. "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
  1270. try_msi:
  1271. /* Trying MSI */
  1272. ret = pci_enable_msi(ha->pdev);
  1273. if (!ret) {
  1274. ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
  1275. 0, DRIVER_NAME, ha);
  1276. if (!ret) {
  1277. DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
  1278. set_bit(AF_MSI_ENABLED, &ha->flags);
  1279. goto irq_attached;
  1280. } else {
  1281. ql4_printk(KERN_WARNING, ha,
  1282. "MSI: Failed to reserve interrupt %d "
  1283. "already in use.\n", ha->pdev->irq);
  1284. pci_disable_msi(ha->pdev);
  1285. }
  1286. }
  1287. /*
  1288. * Prevent interrupts from falling back to INTx mode in cases where
  1289. * interrupts cannot get acquired through MSI-X or MSI mode.
  1290. */
  1291. if (is_qla8022(ha)) {
  1292. ql4_printk(KERN_WARNING, ha, "IRQ not attached -- %d.\n", ret);
  1293. goto irq_not_attached;
  1294. }
  1295. try_intx:
  1296. /* Trying INTx */
  1297. ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
  1298. IRQF_SHARED, DRIVER_NAME, ha);
  1299. if (!ret) {
  1300. DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
  1301. set_bit(AF_INTx_ENABLED, &ha->flags);
  1302. goto irq_attached;
  1303. } else {
  1304. ql4_printk(KERN_WARNING, ha,
  1305. "INTx: Failed to reserve interrupt %d already in"
  1306. " use.\n", ha->pdev->irq);
  1307. goto irq_not_attached;
  1308. }
  1309. irq_attached:
  1310. set_bit(AF_IRQ_ATTACHED, &ha->flags);
  1311. ha->host->irq = ha->pdev->irq;
  1312. ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
  1313. __func__, ha->pdev->irq);
  1314. irq_not_attached:
  1315. return ret;
  1316. }
  1317. void qla4xxx_free_irqs(struct scsi_qla_host *ha)
  1318. {
  1319. if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags)) {
  1320. if (test_bit(AF_MSIX_ENABLED, &ha->flags)) {
  1321. qla4_8xxx_disable_msix(ha);
  1322. } else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
  1323. free_irq(ha->pdev->irq, ha);
  1324. pci_disable_msi(ha->pdev);
  1325. } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags)) {
  1326. free_irq(ha->pdev->irq, ha);
  1327. }
  1328. }
  1329. }