qla_rscn.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2005 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. /**
  9. * IO descriptor handle definitions.
  10. *
  11. * Signature form:
  12. *
  13. * |31------28|27-------------------12|11-------0|
  14. * | Type | Rolling Signature | Index |
  15. * |----------|-----------------------|----------|
  16. *
  17. **/
  18. #define HDL_TYPE_SCSI 0
  19. #define HDL_TYPE_ASYNC_IOCB 0x0A
  20. #define HDL_INDEX_BITS 12
  21. #define HDL_ITER_BITS 16
  22. #define HDL_TYPE_BITS 4
  23. #define HDL_INDEX_MASK ((1UL << HDL_INDEX_BITS) - 1)
  24. #define HDL_ITER_MASK ((1UL << HDL_ITER_BITS) - 1)
  25. #define HDL_TYPE_MASK ((1UL << HDL_TYPE_BITS) - 1)
  26. #define HDL_INDEX_SHIFT 0
  27. #define HDL_ITER_SHIFT (HDL_INDEX_SHIFT + HDL_INDEX_BITS)
  28. #define HDL_TYPE_SHIFT (HDL_ITER_SHIFT + HDL_ITER_BITS)
  29. /* Local Prototypes. */
  30. static inline uint32_t qla2x00_to_handle(uint16_t, uint16_t, uint16_t);
  31. static inline uint16_t qla2x00_handle_to_idx(uint32_t);
  32. static inline uint32_t qla2x00_iodesc_to_handle(struct io_descriptor *);
  33. static inline struct io_descriptor *qla2x00_handle_to_iodesc(scsi_qla_host_t *,
  34. uint32_t);
  35. static inline struct io_descriptor *qla2x00_alloc_iodesc(scsi_qla_host_t *);
  36. static inline void qla2x00_free_iodesc(struct io_descriptor *);
  37. static inline void qla2x00_init_io_descriptors(scsi_qla_host_t *);
  38. static void qla2x00_iodesc_timeout(unsigned long);
  39. static inline void qla2x00_add_iodesc_timer(struct io_descriptor *);
  40. static inline void qla2x00_remove_iodesc_timer(struct io_descriptor *);
  41. static inline void qla2x00_update_login_fcport(scsi_qla_host_t *,
  42. struct mbx_entry *, fc_port_t *);
  43. static int qla2x00_send_abort_iocb(scsi_qla_host_t *, struct io_descriptor *,
  44. uint32_t, int);
  45. static int qla2x00_send_abort_iocb_cb(scsi_qla_host_t *, struct io_descriptor *,
  46. struct mbx_entry *);
  47. static int qla2x00_send_adisc_iocb(scsi_qla_host_t *, struct io_descriptor *,
  48. int);
  49. static int qla2x00_send_adisc_iocb_cb(scsi_qla_host_t *, struct io_descriptor *,
  50. struct mbx_entry *);
  51. static int qla2x00_send_logout_iocb(scsi_qla_host_t *, struct io_descriptor *,
  52. int);
  53. static int qla2x00_send_logout_iocb_cb(scsi_qla_host_t *,
  54. struct io_descriptor *, struct mbx_entry *);
  55. static int qla2x00_send_login_iocb(scsi_qla_host_t *, struct io_descriptor *,
  56. port_id_t *, int);
  57. static int qla2x00_send_login_iocb_cb(scsi_qla_host_t *, struct io_descriptor *,
  58. struct mbx_entry *);
  59. /**
  60. * Mailbox IOCB callback array.
  61. **/
  62. static int (*iocb_function_cb_list[LAST_IOCB_CB])
  63. (scsi_qla_host_t *, struct io_descriptor *, struct mbx_entry *) = {
  64. qla2x00_send_abort_iocb_cb,
  65. qla2x00_send_adisc_iocb_cb,
  66. qla2x00_send_logout_iocb_cb,
  67. qla2x00_send_login_iocb_cb,
  68. };
  69. /**
  70. * Generic IO descriptor handle routines.
  71. **/
  72. /**
  73. * qla2x00_to_handle() - Create a descriptor handle.
  74. * @type: descriptor type
  75. * @iter: descriptor rolling signature
  76. * @idx: index to the descriptor array
  77. *
  78. * Returns a composite handle based in the @type, @iter, and @idx.
  79. */
  80. static inline uint32_t
  81. qla2x00_to_handle(uint16_t type, uint16_t iter, uint16_t idx)
  82. {
  83. return ((uint32_t)(((uint32_t)type << HDL_TYPE_SHIFT) |
  84. ((uint32_t)iter << HDL_ITER_SHIFT) |
  85. ((uint32_t)idx << HDL_INDEX_SHIFT)));
  86. }
  87. /**
  88. * qla2x00_handle_to_idx() - Retrive the index for a given handle.
  89. * @handle: descriptor handle
  90. *
  91. * Returns the index specified by the @handle.
  92. */
  93. static inline uint16_t
  94. qla2x00_handle_to_idx(uint32_t handle)
  95. {
  96. return ((uint16_t)(((handle) >> HDL_INDEX_SHIFT) & HDL_INDEX_MASK));
  97. }
  98. /**
  99. * qla2x00_iodesc_to_handle() - Convert an IO descriptor to a unique handle.
  100. * @iodesc: io descriptor
  101. *
  102. * Returns a unique handle for @iodesc.
  103. */
  104. static inline uint32_t
  105. qla2x00_iodesc_to_handle(struct io_descriptor *iodesc)
  106. {
  107. uint32_t handle;
  108. handle = qla2x00_to_handle(HDL_TYPE_ASYNC_IOCB,
  109. ++iodesc->ha->iodesc_signature, iodesc->idx);
  110. iodesc->signature = handle;
  111. return (handle);
  112. }
  113. /**
  114. * qla2x00_handle_to_iodesc() - Retrieve an IO descriptor given a unique handle.
  115. * @ha: HA context
  116. * @handle: handle to io descriptor
  117. *
  118. * Returns a pointer to the io descriptor, or NULL, if the io descriptor does
  119. * not exist or the io descriptors signature does not @handle.
  120. */
  121. static inline struct io_descriptor *
  122. qla2x00_handle_to_iodesc(scsi_qla_host_t *ha, uint32_t handle)
  123. {
  124. uint16_t idx;
  125. struct io_descriptor *iodesc;
  126. idx = qla2x00_handle_to_idx(handle);
  127. iodesc = &ha->io_descriptors[idx];
  128. if (iodesc)
  129. if (iodesc->signature != handle)
  130. iodesc = NULL;
  131. return (iodesc);
  132. }
  133. /**
  134. * IO descriptor allocation routines.
  135. **/
  136. /**
  137. * qla2x00_alloc_iodesc() - Allocate an IO descriptor from the pool.
  138. * @ha: HA context
  139. *
  140. * Returns a pointer to the allocated io descriptor, or NULL, if none available.
  141. */
  142. static inline struct io_descriptor *
  143. qla2x00_alloc_iodesc(scsi_qla_host_t *ha)
  144. {
  145. uint16_t iter;
  146. struct io_descriptor *iodesc;
  147. iodesc = NULL;
  148. for (iter = 0; iter < MAX_IO_DESCRIPTORS; iter++) {
  149. if (ha->io_descriptors[iter].used)
  150. continue;
  151. iodesc = &ha->io_descriptors[iter];
  152. iodesc->used = 1;
  153. iodesc->idx = iter;
  154. init_timer(&iodesc->timer);
  155. iodesc->ha = ha;
  156. iodesc->signature = qla2x00_iodesc_to_handle(iodesc);
  157. break;
  158. }
  159. return (iodesc);
  160. }
  161. /**
  162. * qla2x00_free_iodesc() - Free an IO descriptor.
  163. * @iodesc: io descriptor
  164. *
  165. * NOTE: The io descriptors timer *must* be stopped before it can be free'd.
  166. */
  167. static inline void
  168. qla2x00_free_iodesc(struct io_descriptor *iodesc)
  169. {
  170. iodesc->used = 0;
  171. iodesc->signature = 0;
  172. }
  173. /**
  174. * qla2x00_remove_iodesc_timer() - Remove an active timer from an IO descriptor.
  175. * @iodesc: io descriptor
  176. */
  177. static inline void
  178. qla2x00_remove_iodesc_timer(struct io_descriptor *iodesc)
  179. {
  180. if (iodesc->timer.function != NULL) {
  181. del_timer_sync(&iodesc->timer);
  182. iodesc->timer.data = (unsigned long) NULL;
  183. iodesc->timer.function = NULL;
  184. }
  185. }
  186. /**
  187. * qla2x00_init_io_descriptors() - Initialize the pool of IO descriptors.
  188. * @ha: HA context
  189. */
  190. static inline void
  191. qla2x00_init_io_descriptors(scsi_qla_host_t *ha)
  192. {
  193. uint16_t iter;
  194. for (iter = 0; iter < MAX_IO_DESCRIPTORS; iter++) {
  195. if (!ha->io_descriptors[iter].used)
  196. continue;
  197. qla2x00_remove_iodesc_timer(&ha->io_descriptors[iter]);
  198. qla2x00_free_iodesc(&ha->io_descriptors[iter]);
  199. }
  200. }
  201. /**
  202. * IO descriptor timer routines.
  203. **/
  204. /**
  205. * qla2x00_iodesc_timeout() - Timeout IO descriptor handler.
  206. * @data: io descriptor
  207. */
  208. static void
  209. qla2x00_iodesc_timeout(unsigned long data)
  210. {
  211. struct io_descriptor *iodesc;
  212. iodesc = (struct io_descriptor *) data;
  213. DEBUG14(printk("scsi(%ld): IO descriptor timeout, index=%x "
  214. "signature=%08x, scheduling ISP abort.\n", iodesc->ha->host_no,
  215. iodesc->idx, iodesc->signature));
  216. qla2x00_free_iodesc(iodesc);
  217. qla_printk(KERN_WARNING, iodesc->ha,
  218. "IO descriptor timeout. Scheduling ISP abort.\n");
  219. set_bit(ISP_ABORT_NEEDED, &iodesc->ha->dpc_flags);
  220. }
  221. /**
  222. * qla2x00_add_iodesc_timer() - Add and start a timer for an IO descriptor.
  223. * @iodesc: io descriptor
  224. *
  225. * NOTE:
  226. * The firmware shall timeout an outstanding mailbox IOCB in 2 * R_A_TOV (in
  227. * tenths of a second) after it hits the wire. But, if there are any request
  228. * resource contraints (i.e. during heavy I/O), exchanges can be held off for
  229. * at most R_A_TOV. Therefore, the driver will wait 4 * R_A_TOV before
  230. * scheduling a recovery (big hammer).
  231. */
  232. static inline void
  233. qla2x00_add_iodesc_timer(struct io_descriptor *iodesc)
  234. {
  235. unsigned long timeout;
  236. timeout = (iodesc->ha->r_a_tov * 4) / 10;
  237. init_timer(&iodesc->timer);
  238. iodesc->timer.data = (unsigned long) iodesc;
  239. iodesc->timer.expires = jiffies + (timeout * HZ);
  240. iodesc->timer.function =
  241. (void (*) (unsigned long)) qla2x00_iodesc_timeout;
  242. add_timer(&iodesc->timer);
  243. }
  244. /**
  245. * IO descriptor support routines.
  246. **/
  247. /**
  248. * qla2x00_update_login_fcport() - Update fcport data after login processing.
  249. * @ha: HA context
  250. * @mbxstat: Mailbox command status IOCB
  251. * @fcport: port to update
  252. */
  253. static inline void
  254. qla2x00_update_login_fcport(scsi_qla_host_t *ha, struct mbx_entry *mbxstat,
  255. fc_port_t *fcport)
  256. {
  257. if (le16_to_cpu(mbxstat->mb1) & BIT_0) {
  258. fcport->port_type = FCT_INITIATOR;
  259. } else {
  260. fcport->port_type = FCT_TARGET;
  261. if (le16_to_cpu(mbxstat->mb1) & BIT_1) {
  262. fcport->flags |= FCF_TAPE_PRESENT;
  263. }
  264. }
  265. fcport->login_retry = 0;
  266. fcport->port_login_retry_count = ha->port_down_retry_count *
  267. PORT_RETRY_TIME;
  268. atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
  269. PORT_RETRY_TIME);
  270. fcport->flags |= FCF_FABRIC_DEVICE;
  271. fcport->flags &= ~FCF_FAILOVER_NEEDED;
  272. fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
  273. atomic_set(&fcport->state, FCS_ONLINE);
  274. }
  275. /**
  276. * Mailbox IOCB commands.
  277. **/
  278. /**
  279. * qla2x00_get_mbx_iocb_entry() - Retrieve an IOCB from the request queue.
  280. * @ha: HA context
  281. * @handle: handle to io descriptor
  282. *
  283. * Returns a pointer to the reqest entry, or NULL, if none were available.
  284. */
  285. static inline struct mbx_entry *
  286. qla2x00_get_mbx_iocb_entry(scsi_qla_host_t *ha, uint32_t handle)
  287. {
  288. uint16_t cnt;
  289. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  290. struct mbx_entry *mbxentry;
  291. mbxentry = NULL;
  292. if (ha->req_q_cnt < 3) {
  293. cnt = qla2x00_debounce_register(ISP_REQ_Q_OUT(ha, reg));
  294. if (ha->req_ring_index < cnt)
  295. ha->req_q_cnt = cnt - ha->req_ring_index;
  296. else
  297. ha->req_q_cnt = ha->request_q_length -
  298. (ha->req_ring_index - cnt);
  299. }
  300. if (ha->req_q_cnt >= 3) {
  301. mbxentry = (struct mbx_entry *)ha->request_ring_ptr;
  302. memset(mbxentry, 0, sizeof(struct mbx_entry));
  303. mbxentry->entry_type = MBX_IOCB_TYPE;
  304. mbxentry->entry_count = 1;
  305. mbxentry->sys_define1 = SOURCE_ASYNC_IOCB;
  306. mbxentry->handle = handle;
  307. }
  308. return (mbxentry);
  309. }
  310. /**
  311. * qla2x00_send_abort_iocb() - Issue an abort IOCB to the firmware.
  312. * @ha: HA context
  313. * @iodesc: io descriptor
  314. * @handle_to_abort: firmware handle to abort
  315. * @ha_locked: is function called with the hardware lock
  316. *
  317. * Returns QLA_SUCCESS if the IOCB was issued.
  318. */
  319. static int
  320. qla2x00_send_abort_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  321. uint32_t handle_to_abort, int ha_locked)
  322. {
  323. unsigned long flags = 0;
  324. struct mbx_entry *mbxentry;
  325. /* Send marker if required. */
  326. if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
  327. return (QLA_FUNCTION_FAILED);
  328. if (!ha_locked)
  329. spin_lock_irqsave(&ha->hardware_lock, flags);
  330. /* Build abort mailbox IOCB. */
  331. mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
  332. if (mbxentry == NULL) {
  333. if (!ha_locked)
  334. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  335. return (QLA_FUNCTION_FAILED);
  336. }
  337. mbxentry->mb0 = __constant_cpu_to_le16(MBC_ABORT_COMMAND);
  338. mbxentry->mb1 = mbxentry->loop_id.extended =
  339. cpu_to_le16(iodesc->remote_fcport->loop_id);
  340. mbxentry->mb2 = LSW(handle_to_abort);
  341. mbxentry->mb3 = MSW(handle_to_abort);
  342. wmb();
  343. qla2x00_add_iodesc_timer(iodesc);
  344. /* Issue command to ISP. */
  345. qla2x00_isp_cmd(ha);
  346. if (!ha_locked)
  347. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  348. DEBUG14(printk("scsi(%ld): Sending Abort IOCB (%08x) to [%x], aborting "
  349. "%08x.\n", ha->host_no, iodesc->signature,
  350. iodesc->remote_fcport->loop_id, handle_to_abort));
  351. return (QLA_SUCCESS);
  352. }
  353. /**
  354. * qla2x00_send_abort_iocb_cb() - Abort IOCB callback.
  355. * @ha: HA context
  356. * @iodesc: io descriptor
  357. * @mbxstat: mailbox status IOCB
  358. *
  359. * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
  360. * will be used for a retry.
  361. */
  362. static int
  363. qla2x00_send_abort_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  364. struct mbx_entry *mbxstat)
  365. {
  366. DEBUG14(printk("scsi(%ld): Abort IOCB -- sent to [%x/%02x%02x%02x], "
  367. "status=%x mb0=%x.\n", ha->host_no, iodesc->remote_fcport->loop_id,
  368. iodesc->d_id.b.domain, iodesc->d_id.b.area, iodesc->d_id.b.al_pa,
  369. le16_to_cpu(mbxstat->status), le16_to_cpu(mbxstat->mb0)));
  370. return (QLA_SUCCESS);
  371. }
  372. /**
  373. * qla2x00_send_adisc_iocb() - Issue a Get Port Database IOCB to the firmware.
  374. * @ha: HA context
  375. * @iodesc: io descriptor
  376. * @ha_locked: is function called with the hardware lock
  377. *
  378. * Returns QLA_SUCCESS if the IOCB was issued.
  379. */
  380. static int
  381. qla2x00_send_adisc_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  382. int ha_locked)
  383. {
  384. unsigned long flags = 0;
  385. struct mbx_entry *mbxentry;
  386. /* Send marker if required. */
  387. if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
  388. return (QLA_FUNCTION_FAILED);
  389. if (!ha_locked)
  390. spin_lock_irqsave(&ha->hardware_lock, flags);
  391. /* Build Get Port Database IOCB. */
  392. mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
  393. if (mbxentry == NULL) {
  394. if (!ha_locked)
  395. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  396. return (QLA_FUNCTION_FAILED);
  397. }
  398. mbxentry->mb0 = __constant_cpu_to_le16(MBC_GET_PORT_DATABASE);
  399. mbxentry->mb1 = mbxentry->loop_id.extended =
  400. cpu_to_le16(iodesc->remote_fcport->loop_id);
  401. mbxentry->mb2 = cpu_to_le16(MSW(LSD(ha->iodesc_pd_dma)));
  402. mbxentry->mb3 = cpu_to_le16(LSW(LSD(ha->iodesc_pd_dma)));
  403. mbxentry->mb6 = cpu_to_le16(MSW(MSD(ha->iodesc_pd_dma)));
  404. mbxentry->mb7 = cpu_to_le16(LSW(MSD(ha->iodesc_pd_dma)));
  405. mbxentry->mb10 = __constant_cpu_to_le16(BIT_0);
  406. wmb();
  407. qla2x00_add_iodesc_timer(iodesc);
  408. /* Issue command to ISP. */
  409. qla2x00_isp_cmd(ha);
  410. if (!ha_locked)
  411. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  412. DEBUG14(printk("scsi(%ld): Sending Adisc IOCB (%08x) to [%x].\n",
  413. ha->host_no, iodesc->signature, iodesc->remote_fcport->loop_id));
  414. return (QLA_SUCCESS);
  415. }
  416. /**
  417. * qla2x00_send_adisc_iocb_cb() - Get Port Database IOCB callback.
  418. * @ha: HA context
  419. * @iodesc: io descriptor
  420. * @mbxstat: mailbox status IOCB
  421. *
  422. * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
  423. * will be used for a retry.
  424. */
  425. static int
  426. qla2x00_send_adisc_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  427. struct mbx_entry *mbxstat)
  428. {
  429. fc_port_t *remote_fcport;
  430. remote_fcport = iodesc->remote_fcport;
  431. /* Ensure the port IDs are consistent. */
  432. if (remote_fcport->d_id.b24 != iodesc->d_id.b24) {
  433. DEBUG14(printk("scsi(%ld): Adisc IOCB -- ignoring, remote port "
  434. "id changed from [%02x%02x%02x] to [%02x%02x%02x].\n",
  435. ha->host_no, remote_fcport->d_id.b.domain,
  436. remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa,
  437. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  438. iodesc->d_id.b.al_pa));
  439. return (QLA_SUCCESS);
  440. }
  441. /* Only process the last command. */
  442. if (remote_fcport->iodesc_idx_sent != iodesc->idx) {
  443. DEBUG14(printk("scsi(%ld): Adisc IOCB -- ignoring, sent to "
  444. "[%02x%02x%02x], expected %x, received %x.\n", ha->host_no,
  445. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  446. iodesc->d_id.b.al_pa, remote_fcport->iodesc_idx_sent,
  447. iodesc->idx));
  448. return (QLA_SUCCESS);
  449. }
  450. if (le16_to_cpu(mbxstat->status) == CS_COMPLETE) {
  451. DEBUG14(printk("scsi(%ld): Adisc IOCB -- marking "
  452. "[%x/%02x%02x%02x] online.\n", ha->host_no,
  453. remote_fcport->loop_id, remote_fcport->d_id.b.domain,
  454. remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa));
  455. atomic_set(&remote_fcport->state, FCS_ONLINE);
  456. } else {
  457. DEBUG14(printk("scsi(%ld): Adisc IOCB -- marking "
  458. "[%x/%02x%02x%02x] lost, status=%x mb0=%x.\n", ha->host_no,
  459. remote_fcport->loop_id, remote_fcport->d_id.b.domain,
  460. remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa,
  461. le16_to_cpu(mbxstat->status), le16_to_cpu(mbxstat->mb0)));
  462. if (atomic_read(&remote_fcport->state) != FCS_DEVICE_DEAD)
  463. atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
  464. }
  465. remote_fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
  466. return (QLA_SUCCESS);
  467. }
  468. /**
  469. * qla2x00_send_logout_iocb() - Issue a fabric port logout IOCB to the firmware.
  470. * @ha: HA context
  471. * @iodesc: io descriptor
  472. * @ha_locked: is function called with the hardware lock
  473. *
  474. * Returns QLA_SUCCESS if the IOCB was issued.
  475. */
  476. static int
  477. qla2x00_send_logout_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  478. int ha_locked)
  479. {
  480. unsigned long flags = 0;
  481. struct mbx_entry *mbxentry;
  482. /* Send marker if required. */
  483. if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
  484. return (QLA_FUNCTION_FAILED);
  485. if (!ha_locked)
  486. spin_lock_irqsave(&ha->hardware_lock, flags);
  487. /* Build fabric port logout mailbox IOCB. */
  488. mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
  489. if (mbxentry == NULL) {
  490. if (!ha_locked)
  491. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  492. return (QLA_FUNCTION_FAILED);
  493. }
  494. mbxentry->mb0 = __constant_cpu_to_le16(MBC_LOGOUT_FABRIC_PORT);
  495. mbxentry->mb1 = mbxentry->loop_id.extended =
  496. cpu_to_le16(iodesc->remote_fcport->loop_id);
  497. wmb();
  498. qla2x00_add_iodesc_timer(iodesc);
  499. /* Issue command to ISP. */
  500. qla2x00_isp_cmd(ha);
  501. if (!ha_locked)
  502. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  503. DEBUG14(printk("scsi(%ld): Sending Logout IOCB (%08x) to [%x].\n",
  504. ha->host_no, iodesc->signature, iodesc->remote_fcport->loop_id));
  505. return (QLA_SUCCESS);
  506. }
  507. /**
  508. * qla2x00_send_logout_iocb_cb() - Fabric port logout IOCB callback.
  509. * @ha: HA context
  510. * @iodesc: io descriptor
  511. * @mbxstat: mailbox status IOCB
  512. *
  513. * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
  514. * will be used for a retry.
  515. */
  516. static int
  517. qla2x00_send_logout_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  518. struct mbx_entry *mbxstat)
  519. {
  520. DEBUG14(printk("scsi(%ld): Logout IOCB -- sent to [%x/%02x%02x%02x], "
  521. "status=%x mb0=%x mb1=%x.\n", ha->host_no,
  522. iodesc->remote_fcport->loop_id,
  523. iodesc->remote_fcport->d_id.b.domain,
  524. iodesc->remote_fcport->d_id.b.area,
  525. iodesc->remote_fcport->d_id.b.al_pa, le16_to_cpu(mbxstat->status),
  526. le16_to_cpu(mbxstat->mb0), le16_to_cpu(mbxstat->mb1)));
  527. return (QLA_SUCCESS);
  528. }
  529. /**
  530. * qla2x00_send_login_iocb() - Issue a fabric port login IOCB to the firmware.
  531. * @ha: HA context
  532. * @iodesc: io descriptor
  533. * @d_id: port id for device
  534. * @ha_locked: is function called with the hardware lock
  535. *
  536. * Returns QLA_SUCCESS if the IOCB was issued.
  537. */
  538. static int
  539. qla2x00_send_login_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  540. port_id_t *d_id, int ha_locked)
  541. {
  542. unsigned long flags = 0;
  543. struct mbx_entry *mbxentry;
  544. /* Send marker if required. */
  545. if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
  546. return (QLA_FUNCTION_FAILED);
  547. if (!ha_locked)
  548. spin_lock_irqsave(&ha->hardware_lock, flags);
  549. /* Build fabric port login mailbox IOCB. */
  550. mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
  551. if (mbxentry == NULL) {
  552. if (!ha_locked)
  553. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  554. return (QLA_FUNCTION_FAILED);
  555. }
  556. mbxentry->mb0 = __constant_cpu_to_le16(MBC_LOGIN_FABRIC_PORT);
  557. mbxentry->mb1 = mbxentry->loop_id.extended =
  558. cpu_to_le16(iodesc->remote_fcport->loop_id);
  559. mbxentry->mb2 = cpu_to_le16(d_id->b.domain);
  560. mbxentry->mb3 = cpu_to_le16(d_id->b.area << 8 | d_id->b.al_pa);
  561. mbxentry->mb10 = __constant_cpu_to_le16(BIT_0);
  562. wmb();
  563. qla2x00_add_iodesc_timer(iodesc);
  564. /* Issue command to ISP. */
  565. qla2x00_isp_cmd(ha);
  566. if (!ha_locked)
  567. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  568. DEBUG14(printk("scsi(%ld): Sending Login IOCB (%08x) to "
  569. "[%x/%02x%02x%02x].\n", ha->host_no, iodesc->signature,
  570. iodesc->remote_fcport->loop_id, d_id->b.domain, d_id->b.area,
  571. d_id->b.al_pa));
  572. return (QLA_SUCCESS);
  573. }
  574. /**
  575. * qla2x00_send_login_iocb_cb() - Fabric port logout IOCB callback.
  576. * @ha: HA context
  577. * @iodesc: io descriptor
  578. * @mbxstat: mailbox status IOCB
  579. *
  580. * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
  581. * will be used for a retry.
  582. */
  583. static int
  584. qla2x00_send_login_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  585. struct mbx_entry *mbxstat)
  586. {
  587. int rval;
  588. fc_port_t *fcport, *remote_fcport, *exist_fcport;
  589. struct io_descriptor *abort_iodesc, *login_iodesc;
  590. uint16_t status, mb[8];
  591. uint16_t reuse;
  592. uint16_t remote_loopid;
  593. port_id_t remote_did, inuse_did;
  594. remote_fcport = iodesc->remote_fcport;
  595. /* Only process the last command. */
  596. if (remote_fcport->iodesc_idx_sent != iodesc->idx) {
  597. DEBUG14(printk("scsi(%ld): Login IOCB -- ignoring, sent to "
  598. "[%02x%02x%02x], expected %x, received %x.\n",
  599. ha->host_no, iodesc->d_id.b.domain, iodesc->d_id.b.area,
  600. iodesc->d_id.b.al_pa, remote_fcport->iodesc_idx_sent,
  601. iodesc->idx));
  602. /* Free RSCN fcport resources. */
  603. if (remote_fcport->port_type == FCT_RSCN) {
  604. DEBUG14(printk("scsi(%ld): Login IOCB -- Freeing RSCN "
  605. "fcport %p [%x/%02x%02x%02x] given ignored Login "
  606. "IOCB.\n", ha->host_no, remote_fcport,
  607. remote_fcport->loop_id,
  608. remote_fcport->d_id.b.domain,
  609. remote_fcport->d_id.b.area,
  610. remote_fcport->d_id.b.al_pa));
  611. list_del(&remote_fcport->list);
  612. kfree(remote_fcport);
  613. }
  614. return (QLA_SUCCESS);
  615. }
  616. status = le16_to_cpu(mbxstat->status);
  617. mb[0] = le16_to_cpu(mbxstat->mb0);
  618. mb[1] = le16_to_cpu(mbxstat->mb1);
  619. mb[2] = le16_to_cpu(mbxstat->mb2);
  620. mb[6] = le16_to_cpu(mbxstat->mb6);
  621. mb[7] = le16_to_cpu(mbxstat->mb7);
  622. /* Good status? */
  623. if ((status == CS_COMPLETE || status == CS_COMPLETE_CHKCOND) &&
  624. mb[0] == MBS_COMMAND_COMPLETE) {
  625. DEBUG14(printk("scsi(%ld): Login IOCB -- status=%x mb1=%x pn="
  626. "%02x%02x%02x%02x%02x%02x%02x%02x.\n", ha->host_no, status,
  627. mb[1], mbxstat->port_name[0], mbxstat->port_name[1],
  628. mbxstat->port_name[2], mbxstat->port_name[3],
  629. mbxstat->port_name[4], mbxstat->port_name[5],
  630. mbxstat->port_name[6], mbxstat->port_name[7]));
  631. memcpy(remote_fcport->node_name, mbxstat->node_name, WWN_SIZE);
  632. memcpy(remote_fcport->port_name, mbxstat->port_name, WWN_SIZE);
  633. /* Is the device already in our fcports list? */
  634. if (remote_fcport->port_type != FCT_RSCN) {
  635. DEBUG14(printk("scsi(%ld): Login IOCB -- marking "
  636. "[%x/%02x%02x%02x] online.\n", ha->host_no,
  637. remote_fcport->loop_id,
  638. remote_fcport->d_id.b.domain,
  639. remote_fcport->d_id.b.area,
  640. remote_fcport->d_id.b.al_pa));
  641. qla2x00_update_login_fcport(ha, mbxstat, remote_fcport);
  642. return (QLA_SUCCESS);
  643. }
  644. /* Does the RSCN portname already exist in our fcports list? */
  645. exist_fcport = NULL;
  646. list_for_each_entry(fcport, &ha->fcports, list) {
  647. if (memcmp(remote_fcport->port_name, fcport->port_name,
  648. WWN_SIZE) == 0) {
  649. exist_fcport = fcport;
  650. break;
  651. }
  652. }
  653. if (exist_fcport != NULL) {
  654. DEBUG14(printk("scsi(%ld): Login IOCB -- found RSCN "
  655. "fcport in fcports list [%p].\n", ha->host_no,
  656. exist_fcport));
  657. /* Abort any ADISC that could have been sent. */
  658. if (exist_fcport->iodesc_idx_sent != iodesc->idx &&
  659. exist_fcport->iodesc_idx_sent <
  660. MAX_IO_DESCRIPTORS &&
  661. ha->io_descriptors[exist_fcport->iodesc_idx_sent].
  662. cb_idx == ADISC_PORT_IOCB_CB) {
  663. abort_iodesc = qla2x00_alloc_iodesc(ha);
  664. if (abort_iodesc) {
  665. DEBUG14(printk("scsi(%ld): Login IOCB "
  666. "-- issuing abort to outstanding "
  667. "Adisc [%x/%02x%02x%02x].\n",
  668. ha->host_no, remote_fcport->loop_id,
  669. exist_fcport->d_id.b.domain,
  670. exist_fcport->d_id.b.area,
  671. exist_fcport->d_id.b.al_pa));
  672. abort_iodesc->cb_idx = ABORT_IOCB_CB;
  673. abort_iodesc->d_id.b24 =
  674. exist_fcport->d_id.b24;
  675. abort_iodesc->remote_fcport =
  676. exist_fcport;
  677. exist_fcport->iodesc_idx_sent =
  678. abort_iodesc->idx;
  679. qla2x00_send_abort_iocb(ha,
  680. abort_iodesc, ha->io_descriptors[
  681. exist_fcport->iodesc_idx_sent].
  682. signature, 1);
  683. } else {
  684. DEBUG14(printk("scsi(%ld): Login IOCB "
  685. "-- unable to abort outstanding "
  686. "Adisc [%x/%02x%02x%02x].\n",
  687. ha->host_no, remote_fcport->loop_id,
  688. exist_fcport->d_id.b.domain,
  689. exist_fcport->d_id.b.area,
  690. exist_fcport->d_id.b.al_pa));
  691. }
  692. }
  693. /*
  694. * If the existing fcport is waiting to send an ADISC
  695. * or LOGIN, then reuse remote fcport (RSCN) to
  696. * continue waiting.
  697. */
  698. reuse = 0;
  699. remote_loopid = remote_fcport->loop_id;
  700. remote_did.b24 = remote_fcport->d_id.b24;
  701. if (exist_fcport->iodesc_idx_sent ==
  702. IODESC_ADISC_NEEDED ||
  703. exist_fcport->iodesc_idx_sent ==
  704. IODESC_LOGIN_NEEDED) {
  705. DEBUG14(printk("scsi(%ld): Login IOCB -- "
  706. "existing fcport [%x/%02x%02x%02x] "
  707. "waiting for IO descriptor, reuse RSCN "
  708. "fcport.\n", ha->host_no,
  709. exist_fcport->loop_id,
  710. exist_fcport->d_id.b.domain,
  711. exist_fcport->d_id.b.area,
  712. exist_fcport->d_id.b.al_pa));
  713. reuse++;
  714. remote_fcport->iodesc_idx_sent =
  715. exist_fcport->iodesc_idx_sent;
  716. exist_fcport->iodesc_idx_sent =
  717. IODESC_INVALID_INDEX;
  718. remote_fcport->loop_id = exist_fcport->loop_id;
  719. remote_fcport->d_id.b24 =
  720. exist_fcport->d_id.b24;
  721. }
  722. /* Logout the old loopid. */
  723. if (!reuse &&
  724. exist_fcport->loop_id != remote_fcport->loop_id &&
  725. exist_fcport->loop_id != FC_NO_LOOP_ID) {
  726. login_iodesc = qla2x00_alloc_iodesc(ha);
  727. if (login_iodesc) {
  728. DEBUG14(printk("scsi(%ld): Login IOCB "
  729. "-- issuing logout to free old "
  730. "loop id [%x/%02x%02x%02x].\n",
  731. ha->host_no, exist_fcport->loop_id,
  732. exist_fcport->d_id.b.domain,
  733. exist_fcport->d_id.b.area,
  734. exist_fcport->d_id.b.al_pa));
  735. login_iodesc->cb_idx =
  736. LOGOUT_PORT_IOCB_CB;
  737. login_iodesc->d_id.b24 =
  738. exist_fcport->d_id.b24;
  739. login_iodesc->remote_fcport =
  740. exist_fcport;
  741. exist_fcport->iodesc_idx_sent =
  742. login_iodesc->idx;
  743. qla2x00_send_logout_iocb(ha,
  744. login_iodesc, 1);
  745. } else {
  746. /* Ran out of IO descriptiors. */
  747. DEBUG14(printk("scsi(%ld): Login IOCB "
  748. "-- unable to logout to free old "
  749. "loop id [%x/%02x%02x%02x].\n",
  750. ha->host_no, exist_fcport->loop_id,
  751. exist_fcport->d_id.b.domain,
  752. exist_fcport->d_id.b.area,
  753. exist_fcport->d_id.b.al_pa));
  754. exist_fcport->iodesc_idx_sent =
  755. IODESC_INVALID_INDEX;
  756. }
  757. }
  758. /* Update existing fcport with remote fcport info. */
  759. DEBUG14(printk("scsi(%ld): Login IOCB -- marking "
  760. "existing fcport [%x/%02x%02x%02x] online.\n",
  761. ha->host_no, remote_loopid, remote_did.b.domain,
  762. remote_did.b.area, remote_did.b.al_pa));
  763. memcpy(exist_fcport->node_name,
  764. remote_fcport->node_name, WWN_SIZE);
  765. exist_fcport->loop_id = remote_loopid;
  766. exist_fcport->d_id.b24 = remote_did.b24;
  767. qla2x00_update_login_fcport(ha, mbxstat, exist_fcport);
  768. /* Finally, free the remote (RSCN) fcport. */
  769. if (!reuse) {
  770. DEBUG14(printk("scsi(%ld): Login IOCB -- "
  771. "Freeing RSCN fcport %p "
  772. "[%x/%02x%02x%02x].\n", ha->host_no,
  773. remote_fcport, remote_fcport->loop_id,
  774. remote_fcport->d_id.b.domain,
  775. remote_fcport->d_id.b.area,
  776. remote_fcport->d_id.b.al_pa));
  777. list_del(&remote_fcport->list);
  778. kfree(remote_fcport);
  779. }
  780. return (QLA_SUCCESS);
  781. }
  782. /*
  783. * A new device has been added, move the RSCN fcport to our
  784. * fcports list.
  785. */
  786. DEBUG14(printk("scsi(%ld): Login IOCB -- adding RSCN fcport "
  787. "[%x/%02x%02x%02x] to fcports list.\n", ha->host_no,
  788. remote_fcport->loop_id, remote_fcport->d_id.b.domain,
  789. remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa));
  790. list_del(&remote_fcport->list);
  791. remote_fcport->flags = (FCF_RLC_SUPPORT | FCF_RESCAN_NEEDED);
  792. qla2x00_update_login_fcport(ha, mbxstat, remote_fcport);
  793. list_add_tail(&remote_fcport->list, &ha->fcports);
  794. set_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags);
  795. } else {
  796. /* Handle login failure. */
  797. if (remote_fcport->login_retry != 0) {
  798. if (mb[0] == MBS_LOOP_ID_USED) {
  799. inuse_did.b.domain = LSB(mb[1]);
  800. inuse_did.b.area = MSB(mb[2]);
  801. inuse_did.b.al_pa = LSB(mb[2]);
  802. DEBUG14(printk("scsi(%ld): Login IOCB -- loop "
  803. "id [%x] used by port id [%02x%02x%02x].\n",
  804. ha->host_no, remote_fcport->loop_id,
  805. inuse_did.b.domain, inuse_did.b.area,
  806. inuse_did.b.al_pa));
  807. if (remote_fcport->d_id.b24 ==
  808. INVALID_PORT_ID) {
  809. /*
  810. * Invalid port id means we are trying
  811. * to login to a remote port with just
  812. * a loop id without knowing about the
  813. * port id. Copy the port id and try
  814. * again.
  815. */
  816. remote_fcport->d_id.b24 = inuse_did.b24;
  817. iodesc->d_id.b24 = inuse_did.b24;
  818. } else {
  819. remote_fcport->loop_id++;
  820. rval = qla2x00_find_new_loop_id(ha,
  821. remote_fcport);
  822. if (rval == QLA_FUNCTION_FAILED) {
  823. /* No more loop ids. */
  824. return (QLA_SUCCESS);
  825. }
  826. }
  827. } else if (mb[0] == MBS_PORT_ID_USED) {
  828. /*
  829. * Device has another loop ID. The firmware
  830. * group recommends the driver perform an
  831. * implicit login with the specified ID.
  832. */
  833. DEBUG14(printk("scsi(%ld): Login IOCB -- port "
  834. "id [%02x%02x%02x] already assigned to "
  835. "loop id [%x].\n", ha->host_no,
  836. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  837. iodesc->d_id.b.al_pa, mb[1]));
  838. remote_fcport->loop_id = mb[1];
  839. } else {
  840. /* Unable to perform login, try again. */
  841. DEBUG14(printk("scsi(%ld): Login IOCB -- "
  842. "failed login [%x/%02x%02x%02x], status=%x "
  843. "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n",
  844. ha->host_no, remote_fcport->loop_id,
  845. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  846. iodesc->d_id.b.al_pa, status, mb[0], mb[1],
  847. mb[2], mb[6], mb[7]));
  848. }
  849. /* Reissue Login with the same IO descriptor. */
  850. iodesc->signature =
  851. qla2x00_iodesc_to_handle(iodesc);
  852. iodesc->cb_idx = LOGIN_PORT_IOCB_CB;
  853. iodesc->d_id.b24 = remote_fcport->d_id.b24;
  854. remote_fcport->iodesc_idx_sent = iodesc->idx;
  855. remote_fcport->login_retry--;
  856. DEBUG14(printk("scsi(%ld): Login IOCB -- retrying "
  857. "login to [%x/%02x%02x%02x] (%d).\n", ha->host_no,
  858. remote_fcport->loop_id,
  859. remote_fcport->d_id.b.domain,
  860. remote_fcport->d_id.b.area,
  861. remote_fcport->d_id.b.al_pa,
  862. remote_fcport->login_retry));
  863. qla2x00_send_login_iocb(ha, iodesc,
  864. &remote_fcport->d_id, 1);
  865. return (QLA_FUNCTION_FAILED);
  866. } else {
  867. /* No more logins, mark device dead. */
  868. DEBUG14(printk("scsi(%ld): Login IOCB -- failed "
  869. "login [%x/%02x%02x%02x] after retries, status=%x "
  870. "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n",
  871. ha->host_no, remote_fcport->loop_id,
  872. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  873. iodesc->d_id.b.al_pa, status, mb[0], mb[1],
  874. mb[2], mb[6], mb[7]));
  875. atomic_set(&remote_fcport->state, FCS_DEVICE_DEAD);
  876. if (remote_fcport->port_type == FCT_RSCN) {
  877. DEBUG14(printk("scsi(%ld): Login IOCB -- "
  878. "Freeing dead RSCN fcport %p "
  879. "[%x/%02x%02x%02x].\n", ha->host_no,
  880. remote_fcport, remote_fcport->loop_id,
  881. remote_fcport->d_id.b.domain,
  882. remote_fcport->d_id.b.area,
  883. remote_fcport->d_id.b.al_pa));
  884. list_del(&remote_fcport->list);
  885. kfree(remote_fcport);
  886. }
  887. }
  888. }
  889. return (QLA_SUCCESS);
  890. }
  891. /**
  892. * IO descriptor processing routines.
  893. **/
  894. /**
  895. * qla2x00_alloc_rscn_fcport() - Allocate an RSCN type fcport.
  896. * @ha: HA context
  897. * @flags: allocation flags
  898. *
  899. * Returns a pointer to the allocated RSCN fcport, or NULL, if none available.
  900. */
  901. fc_port_t *
  902. qla2x00_alloc_rscn_fcport(scsi_qla_host_t *ha, gfp_t flags)
  903. {
  904. fc_port_t *fcport;
  905. fcport = qla2x00_alloc_fcport(ha, flags);
  906. if (fcport == NULL)
  907. return (fcport);
  908. /* Setup RSCN fcport structure. */
  909. fcport->port_type = FCT_RSCN;
  910. return (fcport);
  911. }
  912. /**
  913. * qla2x00_handle_port_rscn() - Handle port RSCN.
  914. * @ha: HA context
  915. * @rscn_entry: RSCN entry
  916. * @fcport: fcport entry to updated
  917. *
  918. * Returns QLA_SUCCESS if the port RSCN was handled.
  919. */
  920. int
  921. qla2x00_handle_port_rscn(scsi_qla_host_t *ha, uint32_t rscn_entry,
  922. fc_port_t *known_fcport, int ha_locked)
  923. {
  924. int rval;
  925. port_id_t rscn_pid;
  926. fc_port_t *fcport, *remote_fcport, *rscn_fcport;
  927. struct io_descriptor *iodesc;
  928. remote_fcport = NULL;
  929. rscn_fcport = NULL;
  930. /* Prepare port id based on incoming entries. */
  931. if (known_fcport) {
  932. rscn_pid.b24 = known_fcport->d_id.b24;
  933. remote_fcport = known_fcport;
  934. DEBUG14(printk("scsi(%ld): Handle RSCN -- process RSCN for "
  935. "fcport [%02x%02x%02x].\n", ha->host_no,
  936. remote_fcport->d_id.b.domain, remote_fcport->d_id.b.area,
  937. remote_fcport->d_id.b.al_pa));
  938. } else {
  939. rscn_pid.b.domain = LSB(MSW(rscn_entry));
  940. rscn_pid.b.area = MSB(LSW(rscn_entry));
  941. rscn_pid.b.al_pa = LSB(LSW(rscn_entry));
  942. DEBUG14(printk("scsi(%ld): Handle RSCN -- process RSCN for "
  943. "port id [%02x%02x%02x].\n", ha->host_no,
  944. rscn_pid.b.domain, rscn_pid.b.area, rscn_pid.b.al_pa));
  945. /*
  946. * Search fcport lists for a known entry at the specified port
  947. * ID.
  948. */
  949. list_for_each_entry(fcport, &ha->fcports, list) {
  950. if (rscn_pid.b24 == fcport->d_id.b24) {
  951. remote_fcport = fcport;
  952. break;
  953. }
  954. }
  955. list_for_each_entry(fcport, &ha->rscn_fcports, list) {
  956. if (rscn_pid.b24 == fcport->d_id.b24) {
  957. rscn_fcport = fcport;
  958. break;
  959. }
  960. }
  961. if (remote_fcport == NULL)
  962. remote_fcport = rscn_fcport;
  963. }
  964. /*
  965. * If the port is already in our fcport list and online, send an ADISC
  966. * to see if it's still alive. Issue login if a new fcport or the known
  967. * fcport is currently offline.
  968. */
  969. if (remote_fcport) {
  970. /*
  971. * No need to send request if the remote fcport is currently
  972. * waiting for an available io descriptor.
  973. */
  974. if (known_fcport == NULL &&
  975. (remote_fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
  976. remote_fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED)) {
  977. /*
  978. * If previous waiting io descriptor is an ADISC, then
  979. * the new RSCN may come from a new remote fcport being
  980. * plugged into the same location.
  981. */
  982. if (remote_fcport->port_type == FCT_RSCN) {
  983. remote_fcport->iodesc_idx_sent =
  984. IODESC_LOGIN_NEEDED;
  985. } else if (remote_fcport->iodesc_idx_sent ==
  986. IODESC_ADISC_NEEDED) {
  987. fc_port_t *new_fcport;
  988. remote_fcport->iodesc_idx_sent =
  989. IODESC_INVALID_INDEX;
  990. /* Create new fcport for later login. */
  991. new_fcport = qla2x00_alloc_rscn_fcport(ha,
  992. ha_locked ? GFP_ATOMIC: GFP_KERNEL);
  993. if (new_fcport) {
  994. DEBUG14(printk("scsi(%ld): Handle RSCN "
  995. "-- creating RSCN fcport %p for "
  996. "future login.\n", ha->host_no,
  997. new_fcport));
  998. new_fcport->d_id.b24 =
  999. remote_fcport->d_id.b24;
  1000. new_fcport->iodesc_idx_sent =
  1001. IODESC_LOGIN_NEEDED;
  1002. list_add_tail(&new_fcport->list,
  1003. &ha->rscn_fcports);
  1004. set_bit(IODESC_PROCESS_NEEDED,
  1005. &ha->dpc_flags);
  1006. } else {
  1007. DEBUG14(printk("scsi(%ld): Handle RSCN "
  1008. "-- unable to allocate RSCN fcport "
  1009. "for future login.\n",
  1010. ha->host_no));
  1011. }
  1012. }
  1013. return (QLA_SUCCESS);
  1014. }
  1015. /* Send ADISC if the fcport is online */
  1016. if (atomic_read(&remote_fcport->state) == FCS_ONLINE ||
  1017. remote_fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED) {
  1018. atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
  1019. iodesc = qla2x00_alloc_iodesc(ha);
  1020. if (iodesc == NULL) {
  1021. /* Mark fcport for later adisc processing */
  1022. DEBUG14(printk("scsi(%ld): Handle RSCN -- not "
  1023. "enough IO descriptors for Adisc, flag "
  1024. "for later processing.\n", ha->host_no));
  1025. remote_fcport->iodesc_idx_sent =
  1026. IODESC_ADISC_NEEDED;
  1027. set_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
  1028. return (QLA_SUCCESS);
  1029. }
  1030. iodesc->cb_idx = ADISC_PORT_IOCB_CB;
  1031. iodesc->d_id.b24 = rscn_pid.b24;
  1032. iodesc->remote_fcport = remote_fcport;
  1033. remote_fcport->iodesc_idx_sent = iodesc->idx;
  1034. qla2x00_send_adisc_iocb(ha, iodesc, ha_locked);
  1035. return (QLA_SUCCESS);
  1036. } else if (remote_fcport->iodesc_idx_sent <
  1037. MAX_IO_DESCRIPTORS &&
  1038. ha->io_descriptors[remote_fcport->iodesc_idx_sent].cb_idx ==
  1039. ADISC_PORT_IOCB_CB) {
  1040. /*
  1041. * Receiving another RSCN while an ADISC is pending,
  1042. * abort the IOCB. Use the same descriptor for the
  1043. * abort.
  1044. */
  1045. uint32_t handle_to_abort;
  1046. iodesc = &ha->io_descriptors[
  1047. remote_fcport->iodesc_idx_sent];
  1048. qla2x00_remove_iodesc_timer(iodesc);
  1049. handle_to_abort = iodesc->signature;
  1050. iodesc->signature = qla2x00_iodesc_to_handle(iodesc);
  1051. iodesc->cb_idx = ABORT_IOCB_CB;
  1052. iodesc->d_id.b24 = remote_fcport->d_id.b24;
  1053. iodesc->remote_fcport = remote_fcport;
  1054. remote_fcport->iodesc_idx_sent = iodesc->idx;
  1055. DEBUG14(printk("scsi(%ld): Handle RSCN -- issuing "
  1056. "abort to outstanding Adisc [%x/%02x%02x%02x].\n",
  1057. ha->host_no, remote_fcport->loop_id,
  1058. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  1059. iodesc->d_id.b.al_pa));
  1060. qla2x00_send_abort_iocb(ha, iodesc, handle_to_abort,
  1061. ha_locked);
  1062. }
  1063. }
  1064. /* We need to login to the remote port, find it. */
  1065. if (known_fcport) {
  1066. remote_fcport = known_fcport;
  1067. } else if (rscn_fcport && rscn_fcport->d_id.b24 != INVALID_PORT_ID &&
  1068. rscn_fcport->iodesc_idx_sent < MAX_IO_DESCRIPTORS &&
  1069. ha->io_descriptors[rscn_fcport->iodesc_idx_sent].cb_idx ==
  1070. LOGIN_PORT_IOCB_CB) {
  1071. /*
  1072. * Ignore duplicate RSCN on fcport which has already
  1073. * initiated a login IOCB.
  1074. */
  1075. DEBUG14(printk("scsi(%ld): Handle RSCN -- ignoring, login "
  1076. "already sent to [%02x%02x%02x].\n", ha->host_no,
  1077. rscn_fcport->d_id.b.domain, rscn_fcport->d_id.b.area,
  1078. rscn_fcport->d_id.b.al_pa));
  1079. return (QLA_SUCCESS);
  1080. } else if (rscn_fcport && rscn_fcport->d_id.b24 != INVALID_PORT_ID &&
  1081. rscn_fcport != remote_fcport) {
  1082. /* Reuse same rscn fcport. */
  1083. DEBUG14(printk("scsi(%ld): Handle RSCN -- reusing RSCN fcport "
  1084. "[%02x%02x%02x].\n", ha->host_no,
  1085. rscn_fcport->d_id.b.domain, rscn_fcport->d_id.b.area,
  1086. rscn_fcport->d_id.b.al_pa));
  1087. remote_fcport = rscn_fcport;
  1088. } else {
  1089. /* Create new fcport for later login. */
  1090. remote_fcport = qla2x00_alloc_rscn_fcport(ha,
  1091. ha_locked ? GFP_ATOMIC: GFP_KERNEL);
  1092. list_add_tail(&remote_fcport->list, &ha->rscn_fcports);
  1093. }
  1094. if (remote_fcport == NULL)
  1095. return (QLA_SUCCESS);
  1096. /* Prepare fcport for login. */
  1097. atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
  1098. remote_fcport->login_retry = 3; /* ha->login_retry_count; */
  1099. remote_fcport->d_id.b24 = rscn_pid.b24;
  1100. iodesc = qla2x00_alloc_iodesc(ha);
  1101. if (iodesc == NULL) {
  1102. /* Mark fcport for later adisc processing. */
  1103. DEBUG14(printk("scsi(%ld): Handle RSCN -- not enough IO "
  1104. "descriptors for Login, flag for later processing.\n",
  1105. ha->host_no));
  1106. remote_fcport->iodesc_idx_sent = IODESC_LOGIN_NEEDED;
  1107. set_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
  1108. return (QLA_SUCCESS);
  1109. }
  1110. if (known_fcport == NULL || rscn_pid.b24 != INVALID_PORT_ID) {
  1111. remote_fcport->loop_id = ha->min_external_loopid;
  1112. rval = qla2x00_find_new_loop_id(ha, remote_fcport);
  1113. if (rval == QLA_FUNCTION_FAILED) {
  1114. /* No more loop ids, failed. */
  1115. DEBUG14(printk("scsi(%ld): Handle RSCN -- no available "
  1116. "loop id to perform Login, failed.\n",
  1117. ha->host_no));
  1118. return (rval);
  1119. }
  1120. }
  1121. iodesc->cb_idx = LOGIN_PORT_IOCB_CB;
  1122. iodesc->d_id.b24 = rscn_pid.b24;
  1123. iodesc->remote_fcport = remote_fcport;
  1124. remote_fcport->iodesc_idx_sent = iodesc->idx;
  1125. DEBUG14(printk("scsi(%ld): Handle RSCN -- attempting login to "
  1126. "[%x/%02x%02x%02x].\n", ha->host_no, remote_fcport->loop_id,
  1127. iodesc->d_id.b.domain, iodesc->d_id.b.area, iodesc->d_id.b.al_pa));
  1128. qla2x00_send_login_iocb(ha, iodesc, &rscn_pid, ha_locked);
  1129. return (QLA_SUCCESS);
  1130. }
  1131. /**
  1132. * qla2x00_process_iodesc() - Complete IO descriptor processing.
  1133. * @ha: HA context
  1134. * @mbxstat: Mailbox IOCB status
  1135. */
  1136. void
  1137. qla2x00_process_iodesc(scsi_qla_host_t *ha, struct mbx_entry *mbxstat)
  1138. {
  1139. int rval;
  1140. uint32_t signature;
  1141. fc_port_t *fcport;
  1142. struct io_descriptor *iodesc;
  1143. signature = mbxstat->handle;
  1144. DEBUG14(printk("scsi(%ld): Process IODesc -- processing %08x.\n",
  1145. ha->host_no, signature));
  1146. /* Retrieve proper IO descriptor. */
  1147. iodesc = qla2x00_handle_to_iodesc(ha, signature);
  1148. if (iodesc == NULL) {
  1149. DEBUG14(printk("scsi(%ld): Process IODesc -- ignoring, "
  1150. "incorrect signature %08x.\n", ha->host_no, signature));
  1151. return;
  1152. }
  1153. /* Stop IO descriptor timer. */
  1154. qla2x00_remove_iodesc_timer(iodesc);
  1155. /* Verify signature match. */
  1156. if (iodesc->signature != signature) {
  1157. DEBUG14(printk("scsi(%ld): Process IODesc -- ignoring, "
  1158. "signature mismatch, sent %08x, received %08x.\n",
  1159. ha->host_no, iodesc->signature, signature));
  1160. return;
  1161. }
  1162. /* Go with IOCB callback. */
  1163. rval = iocb_function_cb_list[iodesc->cb_idx](ha, iodesc, mbxstat);
  1164. if (rval != QLA_SUCCESS) {
  1165. /* IO descriptor reused by callback. */
  1166. return;
  1167. }
  1168. qla2x00_free_iodesc(iodesc);
  1169. if (test_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags)) {
  1170. /* Scan our fcports list for any RSCN requests. */
  1171. list_for_each_entry(fcport, &ha->fcports, list) {
  1172. if (fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
  1173. fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED) {
  1174. qla2x00_handle_port_rscn(ha, 0, fcport, 1);
  1175. return;
  1176. }
  1177. }
  1178. /* Scan our RSCN fcports list for any RSCN requests. */
  1179. list_for_each_entry(fcport, &ha->rscn_fcports, list) {
  1180. if (fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
  1181. fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED) {
  1182. qla2x00_handle_port_rscn(ha, 0, fcport, 1);
  1183. return;
  1184. }
  1185. }
  1186. }
  1187. clear_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
  1188. }
  1189. /**
  1190. * qla2x00_cancel_io_descriptors() - Cancel all outstanding io descriptors.
  1191. * @ha: HA context
  1192. *
  1193. * This routine will also delete any RSCN entries related to the outstanding
  1194. * IO descriptors.
  1195. */
  1196. void
  1197. qla2x00_cancel_io_descriptors(scsi_qla_host_t *ha)
  1198. {
  1199. fc_port_t *fcport, *fcptemp;
  1200. clear_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
  1201. /* Abort all IO descriptors. */
  1202. qla2x00_init_io_descriptors(ha);
  1203. /* Reset all pending IO descriptors in fcports list. */
  1204. list_for_each_entry(fcport, &ha->fcports, list) {
  1205. fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
  1206. }
  1207. /* Reset all pending IO descriptors in rscn fcports list. */
  1208. list_for_each_entry_safe(fcport, fcptemp, &ha->rscn_fcports, list) {
  1209. DEBUG14(printk("scsi(%ld): Cancel IOs -- Freeing RSCN fcport "
  1210. "%p [%x/%02x%02x%02x].\n", ha->host_no, fcport,
  1211. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1212. fcport->d_id.b.al_pa));
  1213. list_del(&fcport->list);
  1214. kfree(fcport);
  1215. }
  1216. }