ql4_isr.c 41 KB

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