ql4_isr.c 40 KB

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