ql4_isr.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2010 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. default:
  687. DEBUG2(printk(KERN_WARNING
  688. "scsi%ld: AEN %04x UNKNOWN\n",
  689. ha->host_no, mbox_sts[0]));
  690. break;
  691. }
  692. } else {
  693. DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
  694. ha->host_no, mbox_status));
  695. ha->mbox_status[0] = mbox_status;
  696. }
  697. }
  698. void qla4_83xx_interrupt_service_routine(struct scsi_qla_host *ha,
  699. uint32_t intr_status)
  700. {
  701. /* Process mailbox/asynch event interrupt.*/
  702. if (intr_status) {
  703. qla4xxx_isr_decode_mailbox(ha,
  704. readl(&ha->qla4_83xx_reg->mailbox_out[0]));
  705. /* clear the interrupt */
  706. writel(0, &ha->qla4_83xx_reg->risc_intr);
  707. } else {
  708. qla4xxx_process_response_queue(ha);
  709. }
  710. /* clear the interrupt */
  711. writel(0, &ha->qla4_83xx_reg->mb_int_mask);
  712. }
  713. /**
  714. * qla4_82xx_interrupt_service_routine - isr
  715. * @ha: pointer to host adapter structure.
  716. *
  717. * This is the main interrupt service routine.
  718. * hardware_lock locked upon entry. runs in interrupt context.
  719. **/
  720. void qla4_82xx_interrupt_service_routine(struct scsi_qla_host *ha,
  721. uint32_t intr_status)
  722. {
  723. /* Process response queue interrupt. */
  724. if (intr_status & HSRX_RISC_IOCB_INT)
  725. qla4xxx_process_response_queue(ha);
  726. /* Process mailbox/asynch event interrupt.*/
  727. if (intr_status & HSRX_RISC_MB_INT)
  728. qla4xxx_isr_decode_mailbox(ha,
  729. readl(&ha->qla4_82xx_reg->mailbox_out[0]));
  730. /* clear the interrupt */
  731. writel(0, &ha->qla4_82xx_reg->host_int);
  732. readl(&ha->qla4_82xx_reg->host_int);
  733. }
  734. /**
  735. * qla4xxx_interrupt_service_routine - isr
  736. * @ha: pointer to host adapter structure.
  737. *
  738. * This is the main interrupt service routine.
  739. * hardware_lock locked upon entry. runs in interrupt context.
  740. **/
  741. void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
  742. uint32_t intr_status)
  743. {
  744. /* Process response queue interrupt. */
  745. if (intr_status & CSR_SCSI_COMPLETION_INTR)
  746. qla4xxx_process_response_queue(ha);
  747. /* Process mailbox/asynch event interrupt.*/
  748. if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
  749. qla4xxx_isr_decode_mailbox(ha,
  750. readl(&ha->reg->mailbox[0]));
  751. /* Clear Mailbox Interrupt */
  752. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  753. &ha->reg->ctrl_status);
  754. readl(&ha->reg->ctrl_status);
  755. }
  756. }
  757. /**
  758. * qla4_82xx_spurious_interrupt - processes spurious interrupt
  759. * @ha: pointer to host adapter structure.
  760. * @reqs_count: .
  761. *
  762. **/
  763. static void qla4_82xx_spurious_interrupt(struct scsi_qla_host *ha,
  764. uint8_t reqs_count)
  765. {
  766. if (reqs_count)
  767. return;
  768. DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
  769. if (is_qla8022(ha)) {
  770. writel(0, &ha->qla4_82xx_reg->host_int);
  771. if (test_bit(AF_INTx_ENABLED, &ha->flags))
  772. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
  773. 0xfbff);
  774. }
  775. ha->spurious_int_count++;
  776. }
  777. /**
  778. * qla4xxx_intr_handler - hardware interrupt handler.
  779. * @irq: Unused
  780. * @dev_id: Pointer to host adapter structure
  781. **/
  782. irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
  783. {
  784. struct scsi_qla_host *ha;
  785. uint32_t intr_status;
  786. unsigned long flags = 0;
  787. uint8_t reqs_count = 0;
  788. ha = (struct scsi_qla_host *) dev_id;
  789. if (!ha) {
  790. DEBUG2(printk(KERN_INFO
  791. "qla4xxx: Interrupt with NULL host ptr\n"));
  792. return IRQ_NONE;
  793. }
  794. spin_lock_irqsave(&ha->hardware_lock, flags);
  795. ha->isr_count++;
  796. /*
  797. * Repeatedly service interrupts up to a maximum of
  798. * MAX_REQS_SERVICED_PER_INTR
  799. */
  800. while (1) {
  801. /*
  802. * Read interrupt status
  803. */
  804. if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
  805. ha->response_out)
  806. intr_status = CSR_SCSI_COMPLETION_INTR;
  807. else
  808. intr_status = readl(&ha->reg->ctrl_status);
  809. if ((intr_status &
  810. (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
  811. if (reqs_count == 0)
  812. ha->spurious_int_count++;
  813. break;
  814. }
  815. if (intr_status & CSR_FATAL_ERROR) {
  816. DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
  817. "Status 0x%04x\n", ha->host_no,
  818. readl(isp_port_error_status (ha))));
  819. /* Issue Soft Reset to clear this error condition.
  820. * This will prevent the RISC from repeatedly
  821. * interrupting the driver; thus, allowing the DPC to
  822. * get scheduled to continue error recovery.
  823. * NOTE: Disabling RISC interrupts does not work in
  824. * this case, as CSR_FATAL_ERROR overrides
  825. * CSR_SCSI_INTR_ENABLE */
  826. if ((readl(&ha->reg->ctrl_status) &
  827. CSR_SCSI_RESET_INTR) == 0) {
  828. writel(set_rmask(CSR_SOFT_RESET),
  829. &ha->reg->ctrl_status);
  830. readl(&ha->reg->ctrl_status);
  831. }
  832. writel(set_rmask(CSR_FATAL_ERROR),
  833. &ha->reg->ctrl_status);
  834. readl(&ha->reg->ctrl_status);
  835. __qla4xxx_disable_intrs(ha);
  836. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  837. break;
  838. } else if (intr_status & CSR_SCSI_RESET_INTR) {
  839. clear_bit(AF_ONLINE, &ha->flags);
  840. __qla4xxx_disable_intrs(ha);
  841. writel(set_rmask(CSR_SCSI_RESET_INTR),
  842. &ha->reg->ctrl_status);
  843. readl(&ha->reg->ctrl_status);
  844. if (!test_bit(AF_HA_REMOVAL, &ha->flags))
  845. set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  846. break;
  847. } else if (intr_status & INTR_PENDING) {
  848. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  849. ha->total_io_count++;
  850. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  851. break;
  852. }
  853. }
  854. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  855. return IRQ_HANDLED;
  856. }
  857. /**
  858. * qla4_82xx_intr_handler - hardware interrupt handler.
  859. * @irq: Unused
  860. * @dev_id: Pointer to host adapter structure
  861. **/
  862. irqreturn_t qla4_82xx_intr_handler(int irq, void *dev_id)
  863. {
  864. struct scsi_qla_host *ha = dev_id;
  865. uint32_t intr_status;
  866. uint32_t status;
  867. unsigned long flags = 0;
  868. uint8_t reqs_count = 0;
  869. if (unlikely(pci_channel_offline(ha->pdev)))
  870. return IRQ_HANDLED;
  871. ha->isr_count++;
  872. status = qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  873. if (!(status & ha->nx_legacy_intr.int_vec_bit))
  874. return IRQ_NONE;
  875. status = qla4_82xx_rd_32(ha, ISR_INT_STATE_REG);
  876. if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
  877. DEBUG2(ql4_printk(KERN_INFO, ha,
  878. "%s legacy Int not triggered\n", __func__));
  879. return IRQ_NONE;
  880. }
  881. /* clear the interrupt */
  882. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  883. /* read twice to ensure write is flushed */
  884. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  885. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  886. spin_lock_irqsave(&ha->hardware_lock, flags);
  887. while (1) {
  888. if (!(readl(&ha->qla4_82xx_reg->host_int) &
  889. ISRX_82XX_RISC_INT)) {
  890. qla4_82xx_spurious_interrupt(ha, reqs_count);
  891. break;
  892. }
  893. intr_status = readl(&ha->qla4_82xx_reg->host_status);
  894. if ((intr_status &
  895. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  896. qla4_82xx_spurious_interrupt(ha, reqs_count);
  897. break;
  898. }
  899. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  900. /* Enable Interrupt */
  901. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
  902. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  903. break;
  904. }
  905. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  906. return IRQ_HANDLED;
  907. }
  908. #define LEG_INT_PTR_B31 (1 << 31)
  909. #define LEG_INT_PTR_B30 (1 << 30)
  910. #define PF_BITS_MASK (0xF << 16)
  911. /**
  912. * qla4_83xx_intr_handler - hardware interrupt handler.
  913. * @irq: Unused
  914. * @dev_id: Pointer to host adapter structure
  915. **/
  916. irqreturn_t qla4_83xx_intr_handler(int irq, void *dev_id)
  917. {
  918. struct scsi_qla_host *ha = dev_id;
  919. uint32_t leg_int_ptr = 0;
  920. unsigned long flags = 0;
  921. ha->isr_count++;
  922. leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
  923. /* Legacy interrupt is valid if bit31 of leg_int_ptr is set */
  924. if (!(leg_int_ptr & LEG_INT_PTR_B31)) {
  925. ql4_printk(KERN_ERR, ha,
  926. "%s: Legacy Interrupt Bit 31 not set, spurious interrupt!\n",
  927. __func__);
  928. return IRQ_NONE;
  929. }
  930. /* Validate the PCIE function ID set in leg_int_ptr bits [19..16] */
  931. if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit) {
  932. ql4_printk(KERN_ERR, ha,
  933. "%s: Incorrect function ID 0x%x in legacy interrupt register, ha->pf_bit = 0x%x\n",
  934. __func__, (leg_int_ptr & PF_BITS_MASK), ha->pf_bit);
  935. return IRQ_NONE;
  936. }
  937. /* To de-assert legacy interrupt, write 0 to Legacy Interrupt Trigger
  938. * Control register and poll till Legacy Interrupt Pointer register
  939. * bit30 is 0.
  940. */
  941. writel(0, &ha->qla4_83xx_reg->leg_int_trig);
  942. do {
  943. leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
  944. if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit)
  945. break;
  946. } while (leg_int_ptr & LEG_INT_PTR_B30);
  947. spin_lock_irqsave(&ha->hardware_lock, flags);
  948. leg_int_ptr = readl(&ha->qla4_83xx_reg->risc_intr);
  949. ha->isp_ops->interrupt_service_routine(ha, leg_int_ptr);
  950. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  951. return IRQ_HANDLED;
  952. }
  953. irqreturn_t
  954. qla4_8xxx_msi_handler(int irq, void *dev_id)
  955. {
  956. struct scsi_qla_host *ha;
  957. ha = (struct scsi_qla_host *) dev_id;
  958. if (!ha) {
  959. DEBUG2(printk(KERN_INFO
  960. "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
  961. return IRQ_NONE;
  962. }
  963. ha->isr_count++;
  964. /* clear the interrupt */
  965. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  966. /* read twice to ensure write is flushed */
  967. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  968. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  969. return qla4_8xxx_default_intr_handler(irq, dev_id);
  970. }
  971. static irqreturn_t qla4_83xx_mailbox_intr_handler(int irq, void *dev_id)
  972. {
  973. struct scsi_qla_host *ha = dev_id;
  974. unsigned long flags;
  975. uint32_t ival = 0;
  976. spin_lock_irqsave(&ha->hardware_lock, flags);
  977. ival = readl(&ha->qla4_83xx_reg->risc_intr);
  978. if (ival == 0) {
  979. ql4_printk(KERN_INFO, ha,
  980. "%s: It is a spurious mailbox interrupt!\n",
  981. __func__);
  982. ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
  983. ival &= ~INT_MASK_FW_MB;
  984. writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
  985. goto exit;
  986. }
  987. qla4xxx_isr_decode_mailbox(ha,
  988. readl(&ha->qla4_83xx_reg->mailbox_out[0]));
  989. writel(0, &ha->qla4_83xx_reg->risc_intr);
  990. ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
  991. ival &= ~INT_MASK_FW_MB;
  992. writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
  993. ha->isr_count++;
  994. exit:
  995. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  996. return IRQ_HANDLED;
  997. }
  998. /**
  999. * qla4_8xxx_default_intr_handler - hardware interrupt handler.
  1000. * @irq: Unused
  1001. * @dev_id: Pointer to host adapter structure
  1002. *
  1003. * This interrupt handler is called directly for MSI-X, and
  1004. * called indirectly for MSI.
  1005. **/
  1006. irqreturn_t
  1007. qla4_8xxx_default_intr_handler(int irq, void *dev_id)
  1008. {
  1009. struct scsi_qla_host *ha = dev_id;
  1010. unsigned long flags;
  1011. uint32_t intr_status;
  1012. uint8_t reqs_count = 0;
  1013. if (is_qla8032(ha)) {
  1014. qla4_83xx_mailbox_intr_handler(irq, dev_id);
  1015. } else {
  1016. spin_lock_irqsave(&ha->hardware_lock, flags);
  1017. while (1) {
  1018. if (!(readl(&ha->qla4_82xx_reg->host_int) &
  1019. ISRX_82XX_RISC_INT)) {
  1020. qla4_82xx_spurious_interrupt(ha, reqs_count);
  1021. break;
  1022. }
  1023. intr_status = readl(&ha->qla4_82xx_reg->host_status);
  1024. if ((intr_status &
  1025. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  1026. qla4_82xx_spurious_interrupt(ha, reqs_count);
  1027. break;
  1028. }
  1029. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  1030. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  1031. break;
  1032. }
  1033. ha->isr_count++;
  1034. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1035. }
  1036. return IRQ_HANDLED;
  1037. }
  1038. irqreturn_t
  1039. qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
  1040. {
  1041. struct scsi_qla_host *ha = dev_id;
  1042. unsigned long flags;
  1043. uint32_t ival = 0;
  1044. spin_lock_irqsave(&ha->hardware_lock, flags);
  1045. if (is_qla8032(ha)) {
  1046. ival = readl(&ha->qla4_83xx_reg->iocb_int_mask);
  1047. if (ival == 0) {
  1048. ql4_printk(KERN_INFO, ha, "%s: It is a spurious iocb interrupt!\n",
  1049. __func__);
  1050. goto exit_msix_rsp_q;
  1051. }
  1052. qla4xxx_process_response_queue(ha);
  1053. writel(0, &ha->qla4_83xx_reg->iocb_int_mask);
  1054. } else {
  1055. qla4xxx_process_response_queue(ha);
  1056. writel(0, &ha->qla4_82xx_reg->host_int);
  1057. }
  1058. ha->isr_count++;
  1059. exit_msix_rsp_q:
  1060. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1061. return IRQ_HANDLED;
  1062. }
  1063. /**
  1064. * qla4xxx_process_aen - processes AENs generated by firmware
  1065. * @ha: pointer to host adapter structure.
  1066. * @process_aen: type of AENs to process
  1067. *
  1068. * Processes specific types of Asynchronous Events generated by firmware.
  1069. * The type of AENs to process is specified by process_aen and can be
  1070. * PROCESS_ALL_AENS 0
  1071. * FLUSH_DDB_CHANGED_AENS 1
  1072. * RELOGIN_DDB_CHANGED_AENS 2
  1073. **/
  1074. void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
  1075. {
  1076. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  1077. struct aen *aen;
  1078. int i;
  1079. unsigned long flags;
  1080. spin_lock_irqsave(&ha->hardware_lock, flags);
  1081. while (ha->aen_out != ha->aen_in) {
  1082. aen = &ha->aen_q[ha->aen_out];
  1083. /* copy aen information to local structure */
  1084. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  1085. mbox_sts[i] = aen->mbox_sts[i];
  1086. ha->aen_q_count++;
  1087. ha->aen_out++;
  1088. if (ha->aen_out == MAX_AEN_ENTRIES)
  1089. ha->aen_out = 0;
  1090. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1091. DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
  1092. " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
  1093. (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
  1094. mbox_sts[0], mbox_sts[1], mbox_sts[2],
  1095. mbox_sts[3], mbox_sts[4]));
  1096. switch (mbox_sts[0]) {
  1097. case MBOX_ASTS_DATABASE_CHANGED:
  1098. switch (process_aen) {
  1099. case FLUSH_DDB_CHANGED_AENS:
  1100. DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
  1101. "[%d] state=%04x FLUSHED!\n",
  1102. ha->host_no, ha->aen_out,
  1103. mbox_sts[0], mbox_sts[2],
  1104. mbox_sts[3]));
  1105. break;
  1106. case PROCESS_ALL_AENS:
  1107. default:
  1108. /* Specific device. */
  1109. if (mbox_sts[1] == 1)
  1110. qla4xxx_process_ddb_changed(ha,
  1111. mbox_sts[2], mbox_sts[3],
  1112. mbox_sts[4]);
  1113. break;
  1114. }
  1115. }
  1116. spin_lock_irqsave(&ha->hardware_lock, flags);
  1117. }
  1118. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1119. }
  1120. int qla4xxx_request_irqs(struct scsi_qla_host *ha)
  1121. {
  1122. int ret;
  1123. if (is_qla40XX(ha))
  1124. goto try_intx;
  1125. if (ql4xenablemsix == 2) {
  1126. /* Note: MSI Interrupts not supported for ISP8324 */
  1127. if (is_qla8032(ha)) {
  1128. ql4_printk(KERN_INFO, ha, "%s: MSI Interrupts not supported for ISP8324, Falling back-to INTx mode\n",
  1129. __func__);
  1130. goto try_intx;
  1131. }
  1132. goto try_msi;
  1133. }
  1134. if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
  1135. goto try_intx;
  1136. /* Trying MSI-X */
  1137. ret = qla4_8xxx_enable_msix(ha);
  1138. if (!ret) {
  1139. DEBUG2(ql4_printk(KERN_INFO, ha,
  1140. "MSI-X: Enabled (0x%X).\n", ha->revision_id));
  1141. goto irq_attached;
  1142. } else {
  1143. if (is_qla8032(ha)) {
  1144. ql4_printk(KERN_INFO, ha, "%s: ISP8324: MSI-X: Falling back-to INTx mode. ret = %d\n",
  1145. __func__, ret);
  1146. goto try_intx;
  1147. }
  1148. }
  1149. ql4_printk(KERN_WARNING, ha,
  1150. "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
  1151. try_msi:
  1152. /* Trying MSI */
  1153. ret = pci_enable_msi(ha->pdev);
  1154. if (!ret) {
  1155. ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
  1156. 0, DRIVER_NAME, ha);
  1157. if (!ret) {
  1158. DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
  1159. set_bit(AF_MSI_ENABLED, &ha->flags);
  1160. goto irq_attached;
  1161. } else {
  1162. ql4_printk(KERN_WARNING, ha,
  1163. "MSI: Failed to reserve interrupt %d "
  1164. "already in use.\n", ha->pdev->irq);
  1165. pci_disable_msi(ha->pdev);
  1166. }
  1167. }
  1168. ql4_printk(KERN_WARNING, ha,
  1169. "MSI: Falling back-to INTx mode -- %d.\n", ret);
  1170. try_intx:
  1171. /* Trying INTx */
  1172. ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
  1173. IRQF_SHARED, DRIVER_NAME, ha);
  1174. if (!ret) {
  1175. DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
  1176. set_bit(AF_INTx_ENABLED, &ha->flags);
  1177. goto irq_attached;
  1178. } else {
  1179. ql4_printk(KERN_WARNING, ha,
  1180. "INTx: Failed to reserve interrupt %d already in"
  1181. " use.\n", ha->pdev->irq);
  1182. return ret;
  1183. }
  1184. irq_attached:
  1185. set_bit(AF_IRQ_ATTACHED, &ha->flags);
  1186. ha->host->irq = ha->pdev->irq;
  1187. ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
  1188. __func__, ha->pdev->irq);
  1189. return ret;
  1190. }
  1191. void qla4xxx_free_irqs(struct scsi_qla_host *ha)
  1192. {
  1193. if (test_bit(AF_MSIX_ENABLED, &ha->flags))
  1194. qla4_8xxx_disable_msix(ha);
  1195. else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
  1196. free_irq(ha->pdev->irq, ha);
  1197. pci_disable_msi(ha->pdev);
  1198. } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags))
  1199. free_irq(ha->pdev->irq, ha);
  1200. }