ql4_isr.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2012 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->req_q_count += task_data->iocb_req_cnt;
  340. ha->iocb_cnt -= task_data->iocb_req_cnt;
  341. queue_work(ha->task_wq, &task_data->task_work);
  342. }
  343. static struct mrb *qla4xxx_del_mrb_from_active_array(struct scsi_qla_host *ha,
  344. uint32_t index)
  345. {
  346. struct mrb *mrb = NULL;
  347. /* validate handle and remove from active array */
  348. if (index >= MAX_MRB)
  349. return mrb;
  350. mrb = ha->active_mrb_array[index];
  351. ha->active_mrb_array[index] = NULL;
  352. if (!mrb)
  353. return mrb;
  354. /* update counters */
  355. ha->req_q_count += mrb->iocb_cnt;
  356. ha->iocb_cnt -= mrb->iocb_cnt;
  357. return mrb;
  358. }
  359. static void qla4xxx_mbox_status_entry(struct scsi_qla_host *ha,
  360. struct mbox_status_iocb *mbox_sts_entry)
  361. {
  362. struct mrb *mrb;
  363. uint32_t status;
  364. uint32_t data_size;
  365. mrb = qla4xxx_del_mrb_from_active_array(ha,
  366. le32_to_cpu(mbox_sts_entry->handle));
  367. if (mrb == NULL) {
  368. ql4_printk(KERN_WARNING, ha, "%s: mrb[%d] is null\n", __func__,
  369. mbox_sts_entry->handle);
  370. return;
  371. }
  372. switch (mrb->mbox_cmd) {
  373. case MBOX_CMD_PING:
  374. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: mbox_cmd = 0x%x, "
  375. "mbox_sts[0] = 0x%x, mbox_sts[6] = 0x%x\n",
  376. __func__, mrb->mbox_cmd,
  377. mbox_sts_entry->out_mbox[0],
  378. mbox_sts_entry->out_mbox[6]));
  379. if (mbox_sts_entry->out_mbox[0] == MBOX_STS_COMMAND_COMPLETE)
  380. status = ISCSI_PING_SUCCESS;
  381. else
  382. status = mbox_sts_entry->out_mbox[6];
  383. data_size = sizeof(mbox_sts_entry->out_mbox);
  384. qla4xxx_post_ping_evt_work(ha, status, mrb->pid, data_size,
  385. (uint8_t *) mbox_sts_entry->out_mbox);
  386. break;
  387. default:
  388. DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: invalid mbox_cmd = "
  389. "0x%x\n", __func__, mrb->mbox_cmd));
  390. }
  391. kfree(mrb);
  392. return;
  393. }
  394. /**
  395. * qla4xxx_process_response_queue - process response queue completions
  396. * @ha: Pointer to host adapter structure.
  397. *
  398. * This routine process response queue completions in interrupt context.
  399. * Hardware_lock locked upon entry
  400. **/
  401. void qla4xxx_process_response_queue(struct scsi_qla_host *ha)
  402. {
  403. uint32_t count = 0;
  404. struct srb *srb = NULL;
  405. struct status_entry *sts_entry;
  406. /* Process all responses from response queue */
  407. while ((ha->response_ptr->signature != RESPONSE_PROCESSED)) {
  408. sts_entry = (struct status_entry *) ha->response_ptr;
  409. count++;
  410. /* Advance pointers for next entry */
  411. if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
  412. ha->response_out = 0;
  413. ha->response_ptr = ha->response_ring;
  414. } else {
  415. ha->response_out++;
  416. ha->response_ptr++;
  417. }
  418. /* process entry */
  419. switch (sts_entry->hdr.entryType) {
  420. case ET_STATUS:
  421. /* Common status */
  422. qla4xxx_status_entry(ha, sts_entry);
  423. break;
  424. case ET_PASSTHRU_STATUS:
  425. if (sts_entry->hdr.systemDefined == SD_ISCSI_PDU)
  426. qla4xxx_passthru_status_entry(ha,
  427. (struct passthru_status *)sts_entry);
  428. else
  429. ql4_printk(KERN_ERR, ha,
  430. "%s: Invalid status received\n",
  431. __func__);
  432. break;
  433. case ET_STATUS_CONTINUATION:
  434. qla4xxx_status_cont_entry(ha,
  435. (struct status_cont_entry *) sts_entry);
  436. break;
  437. case ET_COMMAND:
  438. /* ISP device queue is full. Command not
  439. * accepted by ISP. Queue command for
  440. * later */
  441. srb = qla4xxx_del_from_active_array(ha,
  442. le32_to_cpu(sts_entry->
  443. handle));
  444. if (srb == NULL)
  445. goto exit_prq_invalid_handle;
  446. DEBUG2(printk("scsi%ld: %s: FW device queue full, "
  447. "srb %p\n", ha->host_no, __func__, srb));
  448. /* ETRY normally by sending it back with
  449. * DID_BUS_BUSY */
  450. srb->cmd->result = DID_BUS_BUSY << 16;
  451. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  452. break;
  453. case ET_CONTINUE:
  454. /* Just throw away the continuation entries */
  455. DEBUG2(printk("scsi%ld: %s: Continuation entry - "
  456. "ignoring\n", ha->host_no, __func__));
  457. break;
  458. case ET_MBOX_STATUS:
  459. DEBUG2(ql4_printk(KERN_INFO, ha,
  460. "%s: mbox status IOCB\n", __func__));
  461. qla4xxx_mbox_status_entry(ha,
  462. (struct mbox_status_iocb *)sts_entry);
  463. break;
  464. default:
  465. /*
  466. * Invalid entry in response queue, reset RISC
  467. * firmware.
  468. */
  469. DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
  470. "response queue \n", ha->host_no,
  471. __func__,
  472. sts_entry->hdr.entryType));
  473. goto exit_prq_error;
  474. }
  475. ((struct response *)sts_entry)->signature = RESPONSE_PROCESSED;
  476. wmb();
  477. }
  478. /*
  479. * Tell ISP we're done with response(s). This also clears the interrupt.
  480. */
  481. ha->isp_ops->complete_iocb(ha);
  482. return;
  483. exit_prq_invalid_handle:
  484. DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
  485. ha->host_no, __func__, srb, sts_entry->hdr.entryType,
  486. sts_entry->completionStatus));
  487. exit_prq_error:
  488. ha->isp_ops->complete_iocb(ha);
  489. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  490. }
  491. /**
  492. * qla4xxx_isr_decode_mailbox - decodes mailbox status
  493. * @ha: Pointer to host adapter structure.
  494. * @mailbox_status: Mailbox status.
  495. *
  496. * This routine decodes the mailbox status during the ISR.
  497. * Hardware_lock locked upon entry. runs in interrupt context.
  498. **/
  499. static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
  500. uint32_t mbox_status)
  501. {
  502. int i;
  503. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  504. __le32 __iomem *mailbox_out;
  505. if (is_qla8032(ha))
  506. mailbox_out = &ha->qla4_83xx_reg->mailbox_out[0];
  507. else if (is_qla8022(ha))
  508. mailbox_out = &ha->qla4_82xx_reg->mailbox_out[0];
  509. else
  510. mailbox_out = &ha->reg->mailbox[0];
  511. if ((mbox_status == MBOX_STS_BUSY) ||
  512. (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
  513. (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
  514. ha->mbox_status[0] = mbox_status;
  515. if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
  516. /*
  517. * Copy all mailbox registers to a temporary
  518. * location and set mailbox command done flag
  519. */
  520. for (i = 0; i < ha->mbox_status_count; i++)
  521. ha->mbox_status[i] = readl(&mailbox_out[i]);
  522. set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  523. if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags))
  524. complete(&ha->mbx_intr_comp);
  525. }
  526. } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
  527. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  528. mbox_sts[i] = readl(&mailbox_out[i]);
  529. /* Immediately process the AENs that don't require much work.
  530. * Only queue the database_changed AENs */
  531. if (ha->aen_log.count < MAX_AEN_ENTRIES) {
  532. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  533. ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
  534. mbox_sts[i];
  535. ha->aen_log.count++;
  536. }
  537. switch (mbox_status) {
  538. case MBOX_ASTS_SYSTEM_ERROR:
  539. /* Log Mailbox registers */
  540. ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
  541. qla4xxx_dump_registers(ha);
  542. if ((is_qla8022(ha) && ql4xdontresethba) ||
  543. (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) {
  544. DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
  545. ha->host_no, __func__));
  546. } else {
  547. set_bit(AF_GET_CRASH_RECORD, &ha->flags);
  548. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  549. }
  550. break;
  551. case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
  552. case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
  553. case MBOX_ASTS_NVRAM_INVALID:
  554. case MBOX_ASTS_IP_ADDRESS_CHANGED:
  555. case MBOX_ASTS_DHCP_LEASE_EXPIRED:
  556. DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
  557. "Reset HA\n", ha->host_no, mbox_status));
  558. if (is_qla80XX(ha))
  559. set_bit(DPC_RESET_HA_FW_CONTEXT,
  560. &ha->dpc_flags);
  561. else
  562. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  563. break;
  564. case MBOX_ASTS_LINK_UP:
  565. set_bit(AF_LINK_UP, &ha->flags);
  566. if (test_bit(AF_INIT_DONE, &ha->flags))
  567. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  568. ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
  569. qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKUP,
  570. sizeof(mbox_sts),
  571. (uint8_t *) mbox_sts);
  572. break;
  573. case MBOX_ASTS_LINK_DOWN:
  574. clear_bit(AF_LINK_UP, &ha->flags);
  575. if (test_bit(AF_INIT_DONE, &ha->flags))
  576. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  577. ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
  578. qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKDOWN,
  579. sizeof(mbox_sts),
  580. (uint8_t *) mbox_sts);
  581. break;
  582. case MBOX_ASTS_HEARTBEAT:
  583. ha->seconds_since_last_heartbeat = 0;
  584. break;
  585. case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
  586. DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
  587. "ACQUIRED\n", ha->host_no, mbox_status));
  588. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  589. break;
  590. case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
  591. case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
  592. * mode
  593. * only */
  594. case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
  595. case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
  596. case MBOX_ASTS_SUBNET_STATE_CHANGE:
  597. case MBOX_ASTS_DUPLICATE_IP:
  598. /* No action */
  599. DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
  600. mbox_status));
  601. break;
  602. case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
  603. printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
  604. "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
  605. mbox_sts[2], mbox_sts[3]);
  606. /* mbox_sts[2] = Old ACB state
  607. * mbox_sts[3] = new ACB state */
  608. if ((mbox_sts[3] == ACB_STATE_VALID) &&
  609. ((mbox_sts[2] == ACB_STATE_TENTATIVE) ||
  610. (mbox_sts[2] == ACB_STATE_ACQUIRING)))
  611. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  612. else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
  613. (mbox_sts[2] == ACB_STATE_VALID)) {
  614. if (is_qla80XX(ha))
  615. set_bit(DPC_RESET_HA_FW_CONTEXT,
  616. &ha->dpc_flags);
  617. else
  618. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  619. } else if ((mbox_sts[3] == ACB_STATE_UNCONFIGURED))
  620. complete(&ha->disable_acb_comp);
  621. break;
  622. case MBOX_ASTS_MAC_ADDRESS_CHANGED:
  623. case MBOX_ASTS_DNS:
  624. /* No action */
  625. DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
  626. "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
  627. ha->host_no, mbox_sts[0],
  628. mbox_sts[1], mbox_sts[2]));
  629. break;
  630. case MBOX_ASTS_SELF_TEST_FAILED:
  631. case MBOX_ASTS_LOGIN_FAILED:
  632. /* No action */
  633. DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
  634. "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
  635. ha->host_no, mbox_sts[0], mbox_sts[1],
  636. mbox_sts[2], mbox_sts[3]));
  637. break;
  638. case MBOX_ASTS_DATABASE_CHANGED:
  639. /* Queue AEN information and process it in the DPC
  640. * routine */
  641. if (ha->aen_q_count > 0) {
  642. /* decrement available counter */
  643. ha->aen_q_count--;
  644. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  645. ha->aen_q[ha->aen_in].mbox_sts[i] =
  646. mbox_sts[i];
  647. /* print debug message */
  648. DEBUG2(printk("scsi%ld: AEN[%d] %04x queued "
  649. "mb1:0x%x mb2:0x%x mb3:0x%x "
  650. "mb4:0x%x mb5:0x%x\n",
  651. ha->host_no, ha->aen_in,
  652. mbox_sts[0], mbox_sts[1],
  653. mbox_sts[2], mbox_sts[3],
  654. mbox_sts[4], mbox_sts[5]));
  655. /* advance pointer */
  656. ha->aen_in++;
  657. if (ha->aen_in == MAX_AEN_ENTRIES)
  658. ha->aen_in = 0;
  659. /* The DPC routine will process the aen */
  660. set_bit(DPC_AEN, &ha->dpc_flags);
  661. } else {
  662. DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
  663. "overflowed! AEN LOST!!\n",
  664. ha->host_no, __func__,
  665. mbox_sts[0]));
  666. DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
  667. ha->host_no));
  668. for (i = 0; i < MAX_AEN_ENTRIES; i++) {
  669. DEBUG2(printk("AEN[%d] %04x %04x %04x "
  670. "%04x\n", i, mbox_sts[0],
  671. mbox_sts[1], mbox_sts[2],
  672. mbox_sts[3]));
  673. }
  674. }
  675. break;
  676. case MBOX_ASTS_TXSCVR_INSERTED:
  677. DEBUG2(printk(KERN_WARNING
  678. "scsi%ld: AEN %04x Transceiver"
  679. " inserted\n", ha->host_no, mbox_sts[0]));
  680. break;
  681. case MBOX_ASTS_TXSCVR_REMOVED:
  682. DEBUG2(printk(KERN_WARNING
  683. "scsi%ld: AEN %04x Transceiver"
  684. " removed\n", ha->host_no, mbox_sts[0]));
  685. break;
  686. case MBOX_ASTS_IDC_NOTIFY:
  687. {
  688. uint32_t opcode;
  689. if (is_qla8032(ha)) {
  690. DEBUG2(ql4_printk(KERN_INFO, ha,
  691. "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
  692. ha->host_no, mbox_sts[0],
  693. mbox_sts[1], mbox_sts[2],
  694. mbox_sts[3], mbox_sts[4]));
  695. opcode = mbox_sts[1] >> 16;
  696. if ((opcode == MBOX_CMD_SET_PORT_CONFIG) ||
  697. (opcode == MBOX_CMD_PORT_RESET)) {
  698. set_bit(DPC_POST_IDC_ACK,
  699. &ha->dpc_flags);
  700. ha->idc_info.request_desc = mbox_sts[1];
  701. ha->idc_info.info1 = mbox_sts[2];
  702. ha->idc_info.info2 = mbox_sts[3];
  703. ha->idc_info.info3 = mbox_sts[4];
  704. qla4xxx_wake_dpc(ha);
  705. }
  706. }
  707. break;
  708. }
  709. case MBOX_ASTS_IDC_COMPLETE:
  710. if (is_qla8032(ha)) {
  711. DEBUG2(ql4_printk(KERN_INFO, ha,
  712. "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
  713. ha->host_no, mbox_sts[0],
  714. mbox_sts[1], mbox_sts[2],
  715. mbox_sts[3], mbox_sts[4]));
  716. DEBUG2(ql4_printk(KERN_INFO, ha,
  717. "scsi:%ld: AEN %04x IDC Complete notification\n",
  718. ha->host_no, mbox_sts[0]));
  719. }
  720. break;
  721. default:
  722. DEBUG2(printk(KERN_WARNING
  723. "scsi%ld: AEN %04x UNKNOWN\n",
  724. ha->host_no, mbox_sts[0]));
  725. break;
  726. }
  727. } else {
  728. DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
  729. ha->host_no, mbox_status));
  730. ha->mbox_status[0] = mbox_status;
  731. }
  732. }
  733. void qla4_83xx_interrupt_service_routine(struct scsi_qla_host *ha,
  734. uint32_t intr_status)
  735. {
  736. /* Process mailbox/asynch event interrupt.*/
  737. if (intr_status) {
  738. qla4xxx_isr_decode_mailbox(ha,
  739. readl(&ha->qla4_83xx_reg->mailbox_out[0]));
  740. /* clear the interrupt */
  741. writel(0, &ha->qla4_83xx_reg->risc_intr);
  742. } else {
  743. qla4xxx_process_response_queue(ha);
  744. }
  745. /* clear the interrupt */
  746. writel(0, &ha->qla4_83xx_reg->mb_int_mask);
  747. }
  748. /**
  749. * qla4_82xx_interrupt_service_routine - isr
  750. * @ha: pointer to host adapter structure.
  751. *
  752. * This is the main interrupt service routine.
  753. * hardware_lock locked upon entry. runs in interrupt context.
  754. **/
  755. void qla4_82xx_interrupt_service_routine(struct scsi_qla_host *ha,
  756. uint32_t intr_status)
  757. {
  758. /* Process response queue interrupt. */
  759. if (intr_status & HSRX_RISC_IOCB_INT)
  760. qla4xxx_process_response_queue(ha);
  761. /* Process mailbox/asynch event interrupt.*/
  762. if (intr_status & HSRX_RISC_MB_INT)
  763. qla4xxx_isr_decode_mailbox(ha,
  764. readl(&ha->qla4_82xx_reg->mailbox_out[0]));
  765. /* clear the interrupt */
  766. writel(0, &ha->qla4_82xx_reg->host_int);
  767. readl(&ha->qla4_82xx_reg->host_int);
  768. }
  769. /**
  770. * qla4xxx_interrupt_service_routine - isr
  771. * @ha: pointer to host adapter structure.
  772. *
  773. * This is the main interrupt service routine.
  774. * hardware_lock locked upon entry. runs in interrupt context.
  775. **/
  776. void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
  777. uint32_t intr_status)
  778. {
  779. /* Process response queue interrupt. */
  780. if (intr_status & CSR_SCSI_COMPLETION_INTR)
  781. qla4xxx_process_response_queue(ha);
  782. /* Process mailbox/asynch event interrupt.*/
  783. if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
  784. qla4xxx_isr_decode_mailbox(ha,
  785. readl(&ha->reg->mailbox[0]));
  786. /* Clear Mailbox Interrupt */
  787. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  788. &ha->reg->ctrl_status);
  789. readl(&ha->reg->ctrl_status);
  790. }
  791. }
  792. /**
  793. * qla4_82xx_spurious_interrupt - processes spurious interrupt
  794. * @ha: pointer to host adapter structure.
  795. * @reqs_count: .
  796. *
  797. **/
  798. static void qla4_82xx_spurious_interrupt(struct scsi_qla_host *ha,
  799. uint8_t reqs_count)
  800. {
  801. if (reqs_count)
  802. return;
  803. DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
  804. if (is_qla8022(ha)) {
  805. writel(0, &ha->qla4_82xx_reg->host_int);
  806. if (test_bit(AF_INTx_ENABLED, &ha->flags))
  807. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
  808. 0xfbff);
  809. }
  810. ha->spurious_int_count++;
  811. }
  812. /**
  813. * qla4xxx_intr_handler - hardware interrupt handler.
  814. * @irq: Unused
  815. * @dev_id: Pointer to host adapter structure
  816. **/
  817. irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
  818. {
  819. struct scsi_qla_host *ha;
  820. uint32_t intr_status;
  821. unsigned long flags = 0;
  822. uint8_t reqs_count = 0;
  823. ha = (struct scsi_qla_host *) dev_id;
  824. if (!ha) {
  825. DEBUG2(printk(KERN_INFO
  826. "qla4xxx: Interrupt with NULL host ptr\n"));
  827. return IRQ_NONE;
  828. }
  829. spin_lock_irqsave(&ha->hardware_lock, flags);
  830. ha->isr_count++;
  831. /*
  832. * Repeatedly service interrupts up to a maximum of
  833. * MAX_REQS_SERVICED_PER_INTR
  834. */
  835. while (1) {
  836. /*
  837. * Read interrupt status
  838. */
  839. if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
  840. ha->response_out)
  841. intr_status = CSR_SCSI_COMPLETION_INTR;
  842. else
  843. intr_status = readl(&ha->reg->ctrl_status);
  844. if ((intr_status &
  845. (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
  846. if (reqs_count == 0)
  847. ha->spurious_int_count++;
  848. break;
  849. }
  850. if (intr_status & CSR_FATAL_ERROR) {
  851. DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
  852. "Status 0x%04x\n", ha->host_no,
  853. readl(isp_port_error_status (ha))));
  854. /* Issue Soft Reset to clear this error condition.
  855. * This will prevent the RISC from repeatedly
  856. * interrupting the driver; thus, allowing the DPC to
  857. * get scheduled to continue error recovery.
  858. * NOTE: Disabling RISC interrupts does not work in
  859. * this case, as CSR_FATAL_ERROR overrides
  860. * CSR_SCSI_INTR_ENABLE */
  861. if ((readl(&ha->reg->ctrl_status) &
  862. CSR_SCSI_RESET_INTR) == 0) {
  863. writel(set_rmask(CSR_SOFT_RESET),
  864. &ha->reg->ctrl_status);
  865. readl(&ha->reg->ctrl_status);
  866. }
  867. writel(set_rmask(CSR_FATAL_ERROR),
  868. &ha->reg->ctrl_status);
  869. readl(&ha->reg->ctrl_status);
  870. __qla4xxx_disable_intrs(ha);
  871. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  872. break;
  873. } else if (intr_status & CSR_SCSI_RESET_INTR) {
  874. clear_bit(AF_ONLINE, &ha->flags);
  875. __qla4xxx_disable_intrs(ha);
  876. writel(set_rmask(CSR_SCSI_RESET_INTR),
  877. &ha->reg->ctrl_status);
  878. readl(&ha->reg->ctrl_status);
  879. if (!test_bit(AF_HA_REMOVAL, &ha->flags))
  880. set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  881. break;
  882. } else if (intr_status & INTR_PENDING) {
  883. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  884. ha->total_io_count++;
  885. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  886. break;
  887. }
  888. }
  889. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  890. return IRQ_HANDLED;
  891. }
  892. /**
  893. * qla4_82xx_intr_handler - hardware interrupt handler.
  894. * @irq: Unused
  895. * @dev_id: Pointer to host adapter structure
  896. **/
  897. irqreturn_t qla4_82xx_intr_handler(int irq, void *dev_id)
  898. {
  899. struct scsi_qla_host *ha = dev_id;
  900. uint32_t intr_status;
  901. uint32_t status;
  902. unsigned long flags = 0;
  903. uint8_t reqs_count = 0;
  904. if (unlikely(pci_channel_offline(ha->pdev)))
  905. return IRQ_HANDLED;
  906. ha->isr_count++;
  907. status = qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  908. if (!(status & ha->nx_legacy_intr.int_vec_bit))
  909. return IRQ_NONE;
  910. status = qla4_82xx_rd_32(ha, ISR_INT_STATE_REG);
  911. if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
  912. DEBUG2(ql4_printk(KERN_INFO, ha,
  913. "%s legacy Int not triggered\n", __func__));
  914. return IRQ_NONE;
  915. }
  916. /* clear the interrupt */
  917. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  918. /* read twice to ensure write is flushed */
  919. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  920. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  921. spin_lock_irqsave(&ha->hardware_lock, flags);
  922. while (1) {
  923. if (!(readl(&ha->qla4_82xx_reg->host_int) &
  924. ISRX_82XX_RISC_INT)) {
  925. qla4_82xx_spurious_interrupt(ha, reqs_count);
  926. break;
  927. }
  928. intr_status = readl(&ha->qla4_82xx_reg->host_status);
  929. if ((intr_status &
  930. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  931. qla4_82xx_spurious_interrupt(ha, reqs_count);
  932. break;
  933. }
  934. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  935. /* Enable Interrupt */
  936. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
  937. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  938. break;
  939. }
  940. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  941. return IRQ_HANDLED;
  942. }
  943. #define LEG_INT_PTR_B31 (1 << 31)
  944. #define LEG_INT_PTR_B30 (1 << 30)
  945. #define PF_BITS_MASK (0xF << 16)
  946. /**
  947. * qla4_83xx_intr_handler - hardware interrupt handler.
  948. * @irq: Unused
  949. * @dev_id: Pointer to host adapter structure
  950. **/
  951. irqreturn_t qla4_83xx_intr_handler(int irq, void *dev_id)
  952. {
  953. struct scsi_qla_host *ha = dev_id;
  954. uint32_t leg_int_ptr = 0;
  955. unsigned long flags = 0;
  956. ha->isr_count++;
  957. leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
  958. /* Legacy interrupt is valid if bit31 of leg_int_ptr is set */
  959. if (!(leg_int_ptr & LEG_INT_PTR_B31)) {
  960. ql4_printk(KERN_ERR, ha,
  961. "%s: Legacy Interrupt Bit 31 not set, spurious interrupt!\n",
  962. __func__);
  963. return IRQ_NONE;
  964. }
  965. /* Validate the PCIE function ID set in leg_int_ptr bits [19..16] */
  966. if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit) {
  967. ql4_printk(KERN_ERR, ha,
  968. "%s: Incorrect function ID 0x%x in legacy interrupt register, ha->pf_bit = 0x%x\n",
  969. __func__, (leg_int_ptr & PF_BITS_MASK), ha->pf_bit);
  970. return IRQ_NONE;
  971. }
  972. /* To de-assert legacy interrupt, write 0 to Legacy Interrupt Trigger
  973. * Control register and poll till Legacy Interrupt Pointer register
  974. * bit30 is 0.
  975. */
  976. writel(0, &ha->qla4_83xx_reg->leg_int_trig);
  977. do {
  978. leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
  979. if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit)
  980. break;
  981. } while (leg_int_ptr & LEG_INT_PTR_B30);
  982. spin_lock_irqsave(&ha->hardware_lock, flags);
  983. leg_int_ptr = readl(&ha->qla4_83xx_reg->risc_intr);
  984. ha->isp_ops->interrupt_service_routine(ha, leg_int_ptr);
  985. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  986. return IRQ_HANDLED;
  987. }
  988. irqreturn_t
  989. qla4_8xxx_msi_handler(int irq, void *dev_id)
  990. {
  991. struct scsi_qla_host *ha;
  992. ha = (struct scsi_qla_host *) dev_id;
  993. if (!ha) {
  994. DEBUG2(printk(KERN_INFO
  995. "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
  996. return IRQ_NONE;
  997. }
  998. ha->isr_count++;
  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. return qla4_8xxx_default_intr_handler(irq, dev_id);
  1005. }
  1006. static irqreturn_t qla4_83xx_mailbox_intr_handler(int irq, void *dev_id)
  1007. {
  1008. struct scsi_qla_host *ha = dev_id;
  1009. unsigned long flags;
  1010. uint32_t ival = 0;
  1011. spin_lock_irqsave(&ha->hardware_lock, flags);
  1012. ival = readl(&ha->qla4_83xx_reg->risc_intr);
  1013. if (ival == 0) {
  1014. ql4_printk(KERN_INFO, ha,
  1015. "%s: It is a spurious mailbox interrupt!\n",
  1016. __func__);
  1017. ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
  1018. ival &= ~INT_MASK_FW_MB;
  1019. writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
  1020. goto exit;
  1021. }
  1022. qla4xxx_isr_decode_mailbox(ha,
  1023. readl(&ha->qla4_83xx_reg->mailbox_out[0]));
  1024. writel(0, &ha->qla4_83xx_reg->risc_intr);
  1025. ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
  1026. ival &= ~INT_MASK_FW_MB;
  1027. writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
  1028. ha->isr_count++;
  1029. exit:
  1030. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1031. return IRQ_HANDLED;
  1032. }
  1033. /**
  1034. * qla4_8xxx_default_intr_handler - hardware interrupt handler.
  1035. * @irq: Unused
  1036. * @dev_id: Pointer to host adapter structure
  1037. *
  1038. * This interrupt handler is called directly for MSI-X, and
  1039. * called indirectly for MSI.
  1040. **/
  1041. irqreturn_t
  1042. qla4_8xxx_default_intr_handler(int irq, void *dev_id)
  1043. {
  1044. struct scsi_qla_host *ha = dev_id;
  1045. unsigned long flags;
  1046. uint32_t intr_status;
  1047. uint8_t reqs_count = 0;
  1048. if (is_qla8032(ha)) {
  1049. qla4_83xx_mailbox_intr_handler(irq, dev_id);
  1050. } else {
  1051. spin_lock_irqsave(&ha->hardware_lock, flags);
  1052. while (1) {
  1053. if (!(readl(&ha->qla4_82xx_reg->host_int) &
  1054. ISRX_82XX_RISC_INT)) {
  1055. qla4_82xx_spurious_interrupt(ha, reqs_count);
  1056. break;
  1057. }
  1058. intr_status = readl(&ha->qla4_82xx_reg->host_status);
  1059. if ((intr_status &
  1060. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  1061. qla4_82xx_spurious_interrupt(ha, reqs_count);
  1062. break;
  1063. }
  1064. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  1065. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  1066. break;
  1067. }
  1068. ha->isr_count++;
  1069. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1070. }
  1071. return IRQ_HANDLED;
  1072. }
  1073. irqreturn_t
  1074. qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
  1075. {
  1076. struct scsi_qla_host *ha = dev_id;
  1077. unsigned long flags;
  1078. uint32_t ival = 0;
  1079. spin_lock_irqsave(&ha->hardware_lock, flags);
  1080. if (is_qla8032(ha)) {
  1081. ival = readl(&ha->qla4_83xx_reg->iocb_int_mask);
  1082. if (ival == 0) {
  1083. ql4_printk(KERN_INFO, ha, "%s: It is a spurious iocb interrupt!\n",
  1084. __func__);
  1085. goto exit_msix_rsp_q;
  1086. }
  1087. qla4xxx_process_response_queue(ha);
  1088. writel(0, &ha->qla4_83xx_reg->iocb_int_mask);
  1089. } else {
  1090. qla4xxx_process_response_queue(ha);
  1091. writel(0, &ha->qla4_82xx_reg->host_int);
  1092. }
  1093. ha->isr_count++;
  1094. exit_msix_rsp_q:
  1095. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1096. return IRQ_HANDLED;
  1097. }
  1098. /**
  1099. * qla4xxx_process_aen - processes AENs generated by firmware
  1100. * @ha: pointer to host adapter structure.
  1101. * @process_aen: type of AENs to process
  1102. *
  1103. * Processes specific types of Asynchronous Events generated by firmware.
  1104. * The type of AENs to process is specified by process_aen and can be
  1105. * PROCESS_ALL_AENS 0
  1106. * FLUSH_DDB_CHANGED_AENS 1
  1107. * RELOGIN_DDB_CHANGED_AENS 2
  1108. **/
  1109. void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
  1110. {
  1111. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  1112. struct aen *aen;
  1113. int i;
  1114. unsigned long flags;
  1115. spin_lock_irqsave(&ha->hardware_lock, flags);
  1116. while (ha->aen_out != ha->aen_in) {
  1117. aen = &ha->aen_q[ha->aen_out];
  1118. /* copy aen information to local structure */
  1119. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  1120. mbox_sts[i] = aen->mbox_sts[i];
  1121. ha->aen_q_count++;
  1122. ha->aen_out++;
  1123. if (ha->aen_out == MAX_AEN_ENTRIES)
  1124. ha->aen_out = 0;
  1125. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1126. DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
  1127. " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
  1128. (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
  1129. mbox_sts[0], mbox_sts[1], mbox_sts[2],
  1130. mbox_sts[3], mbox_sts[4]));
  1131. switch (mbox_sts[0]) {
  1132. case MBOX_ASTS_DATABASE_CHANGED:
  1133. switch (process_aen) {
  1134. case FLUSH_DDB_CHANGED_AENS:
  1135. DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
  1136. "[%d] state=%04x FLUSHED!\n",
  1137. ha->host_no, ha->aen_out,
  1138. mbox_sts[0], mbox_sts[2],
  1139. mbox_sts[3]));
  1140. break;
  1141. case PROCESS_ALL_AENS:
  1142. default:
  1143. /* Specific device. */
  1144. if (mbox_sts[1] == 1)
  1145. qla4xxx_process_ddb_changed(ha,
  1146. mbox_sts[2], mbox_sts[3],
  1147. mbox_sts[4]);
  1148. break;
  1149. }
  1150. }
  1151. spin_lock_irqsave(&ha->hardware_lock, flags);
  1152. }
  1153. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1154. }
  1155. int qla4xxx_request_irqs(struct scsi_qla_host *ha)
  1156. {
  1157. int ret;
  1158. if (is_qla40XX(ha))
  1159. goto try_intx;
  1160. if (ql4xenablemsix == 2) {
  1161. /* Note: MSI Interrupts not supported for ISP8324 */
  1162. if (is_qla8032(ha)) {
  1163. ql4_printk(KERN_INFO, ha, "%s: MSI Interrupts not supported for ISP8324, Falling back-to INTx mode\n",
  1164. __func__);
  1165. goto try_intx;
  1166. }
  1167. goto try_msi;
  1168. }
  1169. if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
  1170. goto try_intx;
  1171. /* Trying MSI-X */
  1172. ret = qla4_8xxx_enable_msix(ha);
  1173. if (!ret) {
  1174. DEBUG2(ql4_printk(KERN_INFO, ha,
  1175. "MSI-X: Enabled (0x%X).\n", ha->revision_id));
  1176. goto irq_attached;
  1177. } else {
  1178. if (is_qla8032(ha)) {
  1179. ql4_printk(KERN_INFO, ha, "%s: ISP8324: MSI-X: Falling back-to INTx mode. ret = %d\n",
  1180. __func__, ret);
  1181. goto try_intx;
  1182. }
  1183. }
  1184. ql4_printk(KERN_WARNING, ha,
  1185. "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
  1186. try_msi:
  1187. /* Trying MSI */
  1188. ret = pci_enable_msi(ha->pdev);
  1189. if (!ret) {
  1190. ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
  1191. 0, DRIVER_NAME, ha);
  1192. if (!ret) {
  1193. DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
  1194. set_bit(AF_MSI_ENABLED, &ha->flags);
  1195. goto irq_attached;
  1196. } else {
  1197. ql4_printk(KERN_WARNING, ha,
  1198. "MSI: Failed to reserve interrupt %d "
  1199. "already in use.\n", ha->pdev->irq);
  1200. pci_disable_msi(ha->pdev);
  1201. }
  1202. }
  1203. /*
  1204. * Prevent interrupts from falling back to INTx mode in cases where
  1205. * interrupts cannot get acquired through MSI-X or MSI mode.
  1206. */
  1207. if (is_qla8022(ha)) {
  1208. ql4_printk(KERN_WARNING, ha, "IRQ not attached -- %d.\n", ret);
  1209. goto irq_not_attached;
  1210. }
  1211. try_intx:
  1212. /* Trying INTx */
  1213. ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
  1214. IRQF_SHARED, DRIVER_NAME, ha);
  1215. if (!ret) {
  1216. DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
  1217. set_bit(AF_INTx_ENABLED, &ha->flags);
  1218. goto irq_attached;
  1219. } else {
  1220. ql4_printk(KERN_WARNING, ha,
  1221. "INTx: Failed to reserve interrupt %d already in"
  1222. " use.\n", ha->pdev->irq);
  1223. goto irq_not_attached;
  1224. }
  1225. irq_attached:
  1226. set_bit(AF_IRQ_ATTACHED, &ha->flags);
  1227. ha->host->irq = ha->pdev->irq;
  1228. ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
  1229. __func__, ha->pdev->irq);
  1230. irq_not_attached:
  1231. return ret;
  1232. }
  1233. void qla4xxx_free_irqs(struct scsi_qla_host *ha)
  1234. {
  1235. if (test_bit(AF_MSIX_ENABLED, &ha->flags))
  1236. qla4_8xxx_disable_msix(ha);
  1237. else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
  1238. free_irq(ha->pdev->irq, ha);
  1239. pci_disable_msi(ha->pdev);
  1240. } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags))
  1241. free_irq(ha->pdev->irq, ha);
  1242. }