ql4_isr.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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_qla8022(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. if ((mbox_status == MBOX_STS_BUSY) ||
  505. (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
  506. (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
  507. ha->mbox_status[0] = mbox_status;
  508. if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
  509. /*
  510. * Copy all mailbox registers to a temporary
  511. * location and set mailbox command done flag
  512. */
  513. for (i = 0; i < ha->mbox_status_count; i++)
  514. ha->mbox_status[i] = is_qla8022(ha)
  515. ? readl(&ha->qla4_82xx_reg->mailbox_out[i])
  516. : readl(&ha->reg->mailbox[i]);
  517. set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  518. if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags))
  519. complete(&ha->mbx_intr_comp);
  520. }
  521. } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
  522. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  523. mbox_sts[i] = is_qla8022(ha)
  524. ? readl(&ha->qla4_82xx_reg->mailbox_out[i])
  525. : readl(&ha->reg->mailbox[i]);
  526. /* Immediately process the AENs that don't require much work.
  527. * Only queue the database_changed AENs */
  528. if (ha->aen_log.count < MAX_AEN_ENTRIES) {
  529. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  530. ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
  531. mbox_sts[i];
  532. ha->aen_log.count++;
  533. }
  534. switch (mbox_status) {
  535. case MBOX_ASTS_SYSTEM_ERROR:
  536. /* Log Mailbox registers */
  537. ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
  538. qla4xxx_dump_registers(ha);
  539. if (ql4xdontresethba) {
  540. DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
  541. ha->host_no, __func__));
  542. } else {
  543. set_bit(AF_GET_CRASH_RECORD, &ha->flags);
  544. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  545. }
  546. break;
  547. case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
  548. case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
  549. case MBOX_ASTS_NVRAM_INVALID:
  550. case MBOX_ASTS_IP_ADDRESS_CHANGED:
  551. case MBOX_ASTS_DHCP_LEASE_EXPIRED:
  552. DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
  553. "Reset HA\n", ha->host_no, mbox_status));
  554. if (is_qla8022(ha))
  555. set_bit(DPC_RESET_HA_FW_CONTEXT,
  556. &ha->dpc_flags);
  557. else
  558. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  559. break;
  560. case MBOX_ASTS_LINK_UP:
  561. set_bit(AF_LINK_UP, &ha->flags);
  562. if (test_bit(AF_INIT_DONE, &ha->flags))
  563. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  564. ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
  565. qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKUP,
  566. sizeof(mbox_sts),
  567. (uint8_t *) mbox_sts);
  568. break;
  569. case MBOX_ASTS_LINK_DOWN:
  570. clear_bit(AF_LINK_UP, &ha->flags);
  571. if (test_bit(AF_INIT_DONE, &ha->flags))
  572. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  573. ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
  574. qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKDOWN,
  575. sizeof(mbox_sts),
  576. (uint8_t *) mbox_sts);
  577. break;
  578. case MBOX_ASTS_HEARTBEAT:
  579. ha->seconds_since_last_heartbeat = 0;
  580. break;
  581. case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
  582. DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
  583. "ACQUIRED\n", ha->host_no, mbox_status));
  584. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  585. break;
  586. case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
  587. case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
  588. * mode
  589. * only */
  590. case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
  591. case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
  592. case MBOX_ASTS_SUBNET_STATE_CHANGE:
  593. case MBOX_ASTS_DUPLICATE_IP:
  594. /* No action */
  595. DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
  596. mbox_status));
  597. break;
  598. case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
  599. printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
  600. "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
  601. mbox_sts[2], mbox_sts[3]);
  602. /* mbox_sts[2] = Old ACB state
  603. * mbox_sts[3] = new ACB state */
  604. if ((mbox_sts[3] == ACB_STATE_VALID) &&
  605. ((mbox_sts[2] == ACB_STATE_TENTATIVE) ||
  606. (mbox_sts[2] == ACB_STATE_ACQUIRING)))
  607. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  608. else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
  609. (mbox_sts[2] == ACB_STATE_VALID)) {
  610. if (is_qla8022(ha))
  611. set_bit(DPC_RESET_HA_FW_CONTEXT,
  612. &ha->dpc_flags);
  613. else
  614. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  615. } else if ((mbox_sts[3] == ACB_STATE_UNCONFIGURED))
  616. complete(&ha->disable_acb_comp);
  617. break;
  618. case MBOX_ASTS_MAC_ADDRESS_CHANGED:
  619. case MBOX_ASTS_DNS:
  620. /* No action */
  621. DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
  622. "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
  623. ha->host_no, mbox_sts[0],
  624. mbox_sts[1], mbox_sts[2]));
  625. break;
  626. case MBOX_ASTS_SELF_TEST_FAILED:
  627. case MBOX_ASTS_LOGIN_FAILED:
  628. /* No action */
  629. DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
  630. "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
  631. ha->host_no, mbox_sts[0], mbox_sts[1],
  632. mbox_sts[2], mbox_sts[3]));
  633. break;
  634. case MBOX_ASTS_DATABASE_CHANGED:
  635. /* Queue AEN information and process it in the DPC
  636. * routine */
  637. if (ha->aen_q_count > 0) {
  638. /* decrement available counter */
  639. ha->aen_q_count--;
  640. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  641. ha->aen_q[ha->aen_in].mbox_sts[i] =
  642. mbox_sts[i];
  643. /* print debug message */
  644. DEBUG2(printk("scsi%ld: AEN[%d] %04x queued "
  645. "mb1:0x%x mb2:0x%x mb3:0x%x "
  646. "mb4:0x%x mb5:0x%x\n",
  647. ha->host_no, ha->aen_in,
  648. mbox_sts[0], mbox_sts[1],
  649. mbox_sts[2], mbox_sts[3],
  650. mbox_sts[4], mbox_sts[5]));
  651. /* advance pointer */
  652. ha->aen_in++;
  653. if (ha->aen_in == MAX_AEN_ENTRIES)
  654. ha->aen_in = 0;
  655. /* The DPC routine will process the aen */
  656. set_bit(DPC_AEN, &ha->dpc_flags);
  657. } else {
  658. DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
  659. "overflowed! AEN LOST!!\n",
  660. ha->host_no, __func__,
  661. mbox_sts[0]));
  662. DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
  663. ha->host_no));
  664. for (i = 0; i < MAX_AEN_ENTRIES; i++) {
  665. DEBUG2(printk("AEN[%d] %04x %04x %04x "
  666. "%04x\n", i, mbox_sts[0],
  667. mbox_sts[1], mbox_sts[2],
  668. mbox_sts[3]));
  669. }
  670. }
  671. break;
  672. case MBOX_ASTS_TXSCVR_INSERTED:
  673. DEBUG2(printk(KERN_WARNING
  674. "scsi%ld: AEN %04x Transceiver"
  675. " inserted\n", ha->host_no, mbox_sts[0]));
  676. break;
  677. case MBOX_ASTS_TXSCVR_REMOVED:
  678. DEBUG2(printk(KERN_WARNING
  679. "scsi%ld: AEN %04x Transceiver"
  680. " removed\n", ha->host_no, mbox_sts[0]));
  681. break;
  682. default:
  683. DEBUG2(printk(KERN_WARNING
  684. "scsi%ld: AEN %04x UNKNOWN\n",
  685. ha->host_no, mbox_sts[0]));
  686. break;
  687. }
  688. } else {
  689. DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
  690. ha->host_no, mbox_status));
  691. ha->mbox_status[0] = mbox_status;
  692. }
  693. }
  694. /**
  695. * qla4_82xx_interrupt_service_routine - isr
  696. * @ha: pointer to host adapter structure.
  697. *
  698. * This is the main interrupt service routine.
  699. * hardware_lock locked upon entry. runs in interrupt context.
  700. **/
  701. void qla4_82xx_interrupt_service_routine(struct scsi_qla_host *ha,
  702. uint32_t intr_status)
  703. {
  704. /* Process response queue interrupt. */
  705. if (intr_status & HSRX_RISC_IOCB_INT)
  706. qla4xxx_process_response_queue(ha);
  707. /* Process mailbox/asynch event interrupt.*/
  708. if (intr_status & HSRX_RISC_MB_INT)
  709. qla4xxx_isr_decode_mailbox(ha,
  710. readl(&ha->qla4_82xx_reg->mailbox_out[0]));
  711. /* clear the interrupt */
  712. writel(0, &ha->qla4_82xx_reg->host_int);
  713. readl(&ha->qla4_82xx_reg->host_int);
  714. }
  715. /**
  716. * qla4xxx_interrupt_service_routine - isr
  717. * @ha: pointer to host adapter structure.
  718. *
  719. * This is the main interrupt service routine.
  720. * hardware_lock locked upon entry. runs in interrupt context.
  721. **/
  722. void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
  723. uint32_t intr_status)
  724. {
  725. /* Process response queue interrupt. */
  726. if (intr_status & CSR_SCSI_COMPLETION_INTR)
  727. qla4xxx_process_response_queue(ha);
  728. /* Process mailbox/asynch event interrupt.*/
  729. if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
  730. qla4xxx_isr_decode_mailbox(ha,
  731. readl(&ha->reg->mailbox[0]));
  732. /* Clear Mailbox Interrupt */
  733. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  734. &ha->reg->ctrl_status);
  735. readl(&ha->reg->ctrl_status);
  736. }
  737. }
  738. /**
  739. * qla4_82xx_spurious_interrupt - processes spurious interrupt
  740. * @ha: pointer to host adapter structure.
  741. * @reqs_count: .
  742. *
  743. **/
  744. static void qla4_82xx_spurious_interrupt(struct scsi_qla_host *ha,
  745. uint8_t reqs_count)
  746. {
  747. if (reqs_count)
  748. return;
  749. DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
  750. if (is_qla8022(ha)) {
  751. writel(0, &ha->qla4_82xx_reg->host_int);
  752. if (test_bit(AF_INTx_ENABLED, &ha->flags))
  753. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
  754. 0xfbff);
  755. }
  756. ha->spurious_int_count++;
  757. }
  758. /**
  759. * qla4xxx_intr_handler - hardware interrupt handler.
  760. * @irq: Unused
  761. * @dev_id: Pointer to host adapter structure
  762. **/
  763. irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
  764. {
  765. struct scsi_qla_host *ha;
  766. uint32_t intr_status;
  767. unsigned long flags = 0;
  768. uint8_t reqs_count = 0;
  769. ha = (struct scsi_qla_host *) dev_id;
  770. if (!ha) {
  771. DEBUG2(printk(KERN_INFO
  772. "qla4xxx: Interrupt with NULL host ptr\n"));
  773. return IRQ_NONE;
  774. }
  775. spin_lock_irqsave(&ha->hardware_lock, flags);
  776. ha->isr_count++;
  777. /*
  778. * Repeatedly service interrupts up to a maximum of
  779. * MAX_REQS_SERVICED_PER_INTR
  780. */
  781. while (1) {
  782. /*
  783. * Read interrupt status
  784. */
  785. if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
  786. ha->response_out)
  787. intr_status = CSR_SCSI_COMPLETION_INTR;
  788. else
  789. intr_status = readl(&ha->reg->ctrl_status);
  790. if ((intr_status &
  791. (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
  792. if (reqs_count == 0)
  793. ha->spurious_int_count++;
  794. break;
  795. }
  796. if (intr_status & CSR_FATAL_ERROR) {
  797. DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
  798. "Status 0x%04x\n", ha->host_no,
  799. readl(isp_port_error_status (ha))));
  800. /* Issue Soft Reset to clear this error condition.
  801. * This will prevent the RISC from repeatedly
  802. * interrupting the driver; thus, allowing the DPC to
  803. * get scheduled to continue error recovery.
  804. * NOTE: Disabling RISC interrupts does not work in
  805. * this case, as CSR_FATAL_ERROR overrides
  806. * CSR_SCSI_INTR_ENABLE */
  807. if ((readl(&ha->reg->ctrl_status) &
  808. CSR_SCSI_RESET_INTR) == 0) {
  809. writel(set_rmask(CSR_SOFT_RESET),
  810. &ha->reg->ctrl_status);
  811. readl(&ha->reg->ctrl_status);
  812. }
  813. writel(set_rmask(CSR_FATAL_ERROR),
  814. &ha->reg->ctrl_status);
  815. readl(&ha->reg->ctrl_status);
  816. __qla4xxx_disable_intrs(ha);
  817. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  818. break;
  819. } else if (intr_status & CSR_SCSI_RESET_INTR) {
  820. clear_bit(AF_ONLINE, &ha->flags);
  821. __qla4xxx_disable_intrs(ha);
  822. writel(set_rmask(CSR_SCSI_RESET_INTR),
  823. &ha->reg->ctrl_status);
  824. readl(&ha->reg->ctrl_status);
  825. if (!test_bit(AF_HA_REMOVAL, &ha->flags))
  826. set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  827. break;
  828. } else if (intr_status & INTR_PENDING) {
  829. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  830. ha->total_io_count++;
  831. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  832. break;
  833. }
  834. }
  835. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  836. return IRQ_HANDLED;
  837. }
  838. /**
  839. * qla4_82xx_intr_handler - hardware interrupt handler.
  840. * @irq: Unused
  841. * @dev_id: Pointer to host adapter structure
  842. **/
  843. irqreturn_t qla4_82xx_intr_handler(int irq, void *dev_id)
  844. {
  845. struct scsi_qla_host *ha = dev_id;
  846. uint32_t intr_status;
  847. uint32_t status;
  848. unsigned long flags = 0;
  849. uint8_t reqs_count = 0;
  850. if (unlikely(pci_channel_offline(ha->pdev)))
  851. return IRQ_HANDLED;
  852. ha->isr_count++;
  853. status = qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  854. if (!(status & ha->nx_legacy_intr.int_vec_bit))
  855. return IRQ_NONE;
  856. status = qla4_82xx_rd_32(ha, ISR_INT_STATE_REG);
  857. if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
  858. DEBUG2(ql4_printk(KERN_INFO, ha,
  859. "%s legacy Int not triggered\n", __func__));
  860. return IRQ_NONE;
  861. }
  862. /* clear the interrupt */
  863. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  864. /* read twice to ensure write is flushed */
  865. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  866. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  867. spin_lock_irqsave(&ha->hardware_lock, flags);
  868. while (1) {
  869. if (!(readl(&ha->qla4_82xx_reg->host_int) &
  870. ISRX_82XX_RISC_INT)) {
  871. qla4_82xx_spurious_interrupt(ha, reqs_count);
  872. break;
  873. }
  874. intr_status = readl(&ha->qla4_82xx_reg->host_status);
  875. if ((intr_status &
  876. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  877. qla4_82xx_spurious_interrupt(ha, reqs_count);
  878. break;
  879. }
  880. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  881. /* Enable Interrupt */
  882. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
  883. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  884. break;
  885. }
  886. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  887. return IRQ_HANDLED;
  888. }
  889. irqreturn_t
  890. qla4_8xxx_msi_handler(int irq, void *dev_id)
  891. {
  892. struct scsi_qla_host *ha;
  893. ha = (struct scsi_qla_host *) dev_id;
  894. if (!ha) {
  895. DEBUG2(printk(KERN_INFO
  896. "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
  897. return IRQ_NONE;
  898. }
  899. ha->isr_count++;
  900. /* clear the interrupt */
  901. qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  902. /* read twice to ensure write is flushed */
  903. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  904. qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
  905. return qla4_8xxx_default_intr_handler(irq, dev_id);
  906. }
  907. /**
  908. * qla4_8xxx_default_intr_handler - hardware interrupt handler.
  909. * @irq: Unused
  910. * @dev_id: Pointer to host adapter structure
  911. *
  912. * This interrupt handler is called directly for MSI-X, and
  913. * called indirectly for MSI.
  914. **/
  915. irqreturn_t
  916. qla4_8xxx_default_intr_handler(int irq, void *dev_id)
  917. {
  918. struct scsi_qla_host *ha = dev_id;
  919. unsigned long flags;
  920. uint32_t intr_status;
  921. uint8_t reqs_count = 0;
  922. spin_lock_irqsave(&ha->hardware_lock, flags);
  923. while (1) {
  924. if (!(readl(&ha->qla4_82xx_reg->host_int) &
  925. ISRX_82XX_RISC_INT)) {
  926. qla4_82xx_spurious_interrupt(ha, reqs_count);
  927. break;
  928. }
  929. intr_status = readl(&ha->qla4_82xx_reg->host_status);
  930. if ((intr_status &
  931. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  932. qla4_82xx_spurious_interrupt(ha, reqs_count);
  933. break;
  934. }
  935. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  936. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  937. break;
  938. }
  939. ha->isr_count++;
  940. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  941. return IRQ_HANDLED;
  942. }
  943. irqreturn_t
  944. qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
  945. {
  946. struct scsi_qla_host *ha = dev_id;
  947. unsigned long flags;
  948. spin_lock_irqsave(&ha->hardware_lock, flags);
  949. qla4xxx_process_response_queue(ha);
  950. writel(0, &ha->qla4_82xx_reg->host_int);
  951. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  952. ha->isr_count++;
  953. return IRQ_HANDLED;
  954. }
  955. /**
  956. * qla4xxx_process_aen - processes AENs generated by firmware
  957. * @ha: pointer to host adapter structure.
  958. * @process_aen: type of AENs to process
  959. *
  960. * Processes specific types of Asynchronous Events generated by firmware.
  961. * The type of AENs to process is specified by process_aen and can be
  962. * PROCESS_ALL_AENS 0
  963. * FLUSH_DDB_CHANGED_AENS 1
  964. * RELOGIN_DDB_CHANGED_AENS 2
  965. **/
  966. void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
  967. {
  968. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  969. struct aen *aen;
  970. int i;
  971. unsigned long flags;
  972. spin_lock_irqsave(&ha->hardware_lock, flags);
  973. while (ha->aen_out != ha->aen_in) {
  974. aen = &ha->aen_q[ha->aen_out];
  975. /* copy aen information to local structure */
  976. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  977. mbox_sts[i] = aen->mbox_sts[i];
  978. ha->aen_q_count++;
  979. ha->aen_out++;
  980. if (ha->aen_out == MAX_AEN_ENTRIES)
  981. ha->aen_out = 0;
  982. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  983. DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
  984. " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
  985. (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
  986. mbox_sts[0], mbox_sts[1], mbox_sts[2],
  987. mbox_sts[3], mbox_sts[4]));
  988. switch (mbox_sts[0]) {
  989. case MBOX_ASTS_DATABASE_CHANGED:
  990. switch (process_aen) {
  991. case FLUSH_DDB_CHANGED_AENS:
  992. DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
  993. "[%d] state=%04x FLUSHED!\n",
  994. ha->host_no, ha->aen_out,
  995. mbox_sts[0], mbox_sts[2],
  996. mbox_sts[3]));
  997. break;
  998. case PROCESS_ALL_AENS:
  999. default:
  1000. /* Specific device. */
  1001. if (mbox_sts[1] == 1)
  1002. qla4xxx_process_ddb_changed(ha,
  1003. mbox_sts[2], mbox_sts[3],
  1004. mbox_sts[4]);
  1005. break;
  1006. }
  1007. }
  1008. spin_lock_irqsave(&ha->hardware_lock, flags);
  1009. }
  1010. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1011. }
  1012. int qla4xxx_request_irqs(struct scsi_qla_host *ha)
  1013. {
  1014. int ret;
  1015. if (!is_qla8022(ha))
  1016. goto try_intx;
  1017. if (ql4xenablemsix == 2)
  1018. goto try_msi;
  1019. if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
  1020. goto try_intx;
  1021. /* Trying MSI-X */
  1022. ret = qla4_8xxx_enable_msix(ha);
  1023. if (!ret) {
  1024. DEBUG2(ql4_printk(KERN_INFO, ha,
  1025. "MSI-X: Enabled (0x%X).\n", ha->revision_id));
  1026. goto irq_attached;
  1027. }
  1028. ql4_printk(KERN_WARNING, ha,
  1029. "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
  1030. try_msi:
  1031. /* Trying MSI */
  1032. ret = pci_enable_msi(ha->pdev);
  1033. if (!ret) {
  1034. ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
  1035. 0, DRIVER_NAME, ha);
  1036. if (!ret) {
  1037. DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
  1038. set_bit(AF_MSI_ENABLED, &ha->flags);
  1039. goto irq_attached;
  1040. } else {
  1041. ql4_printk(KERN_WARNING, ha,
  1042. "MSI: Failed to reserve interrupt %d "
  1043. "already in use.\n", ha->pdev->irq);
  1044. pci_disable_msi(ha->pdev);
  1045. }
  1046. }
  1047. ql4_printk(KERN_WARNING, ha,
  1048. "MSI: Falling back-to INTx mode -- %d.\n", ret);
  1049. try_intx:
  1050. /* Trying INTx */
  1051. ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
  1052. IRQF_SHARED, DRIVER_NAME, ha);
  1053. if (!ret) {
  1054. DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
  1055. set_bit(AF_INTx_ENABLED, &ha->flags);
  1056. goto irq_attached;
  1057. } else {
  1058. ql4_printk(KERN_WARNING, ha,
  1059. "INTx: Failed to reserve interrupt %d already in"
  1060. " use.\n", ha->pdev->irq);
  1061. return ret;
  1062. }
  1063. irq_attached:
  1064. set_bit(AF_IRQ_ATTACHED, &ha->flags);
  1065. ha->host->irq = ha->pdev->irq;
  1066. ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
  1067. __func__, ha->pdev->irq);
  1068. return ret;
  1069. }
  1070. void qla4xxx_free_irqs(struct scsi_qla_host *ha)
  1071. {
  1072. if (test_bit(AF_MSIX_ENABLED, &ha->flags))
  1073. qla4_8xxx_disable_msix(ha);
  1074. else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
  1075. free_irq(ha->pdev->irq, ha);
  1076. pci_disable_msi(ha->pdev);
  1077. } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags))
  1078. free_irq(ha->pdev->irq, ha);
  1079. }