qla_rscn.c 41 KB

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