qla_rscn.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  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. schedule_work(&fcport->rport_add_work);
  275. }
  276. /**
  277. * Mailbox IOCB commands.
  278. **/
  279. /**
  280. * qla2x00_get_mbx_iocb_entry() - Retrieve an IOCB from the request queue.
  281. * @ha: HA context
  282. * @handle: handle to io descriptor
  283. *
  284. * Returns a pointer to the reqest entry, or NULL, if none were available.
  285. */
  286. static inline struct mbx_entry *
  287. qla2x00_get_mbx_iocb_entry(scsi_qla_host_t *ha, uint32_t handle)
  288. {
  289. uint16_t cnt;
  290. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  291. struct mbx_entry *mbxentry;
  292. mbxentry = NULL;
  293. if (ha->req_q_cnt < 3) {
  294. cnt = qla2x00_debounce_register(ISP_REQ_Q_OUT(ha, reg));
  295. if (ha->req_ring_index < cnt)
  296. ha->req_q_cnt = cnt - ha->req_ring_index;
  297. else
  298. ha->req_q_cnt = ha->request_q_length -
  299. (ha->req_ring_index - cnt);
  300. }
  301. if (ha->req_q_cnt >= 3) {
  302. mbxentry = (struct mbx_entry *)ha->request_ring_ptr;
  303. memset(mbxentry, 0, sizeof(struct mbx_entry));
  304. mbxentry->entry_type = MBX_IOCB_TYPE;
  305. mbxentry->entry_count = 1;
  306. mbxentry->sys_define1 = SOURCE_ASYNC_IOCB;
  307. mbxentry->handle = handle;
  308. }
  309. return (mbxentry);
  310. }
  311. /**
  312. * qla2x00_send_abort_iocb() - Issue an abort IOCB to the firmware.
  313. * @ha: HA context
  314. * @iodesc: io descriptor
  315. * @handle_to_abort: firmware handle to abort
  316. * @ha_locked: is function called with the hardware lock
  317. *
  318. * Returns QLA_SUCCESS if the IOCB was issued.
  319. */
  320. static int
  321. qla2x00_send_abort_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  322. uint32_t handle_to_abort, int ha_locked)
  323. {
  324. unsigned long flags = 0;
  325. struct mbx_entry *mbxentry;
  326. /* Send marker if required. */
  327. if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
  328. return (QLA_FUNCTION_FAILED);
  329. if (!ha_locked)
  330. spin_lock_irqsave(&ha->hardware_lock, flags);
  331. /* Build abort mailbox IOCB. */
  332. mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
  333. if (mbxentry == NULL) {
  334. if (!ha_locked)
  335. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  336. return (QLA_FUNCTION_FAILED);
  337. }
  338. mbxentry->mb0 = __constant_cpu_to_le16(MBC_ABORT_COMMAND);
  339. mbxentry->mb1 = mbxentry->loop_id.extended =
  340. cpu_to_le16(iodesc->remote_fcport->loop_id);
  341. mbxentry->mb2 = LSW(handle_to_abort);
  342. mbxentry->mb3 = MSW(handle_to_abort);
  343. wmb();
  344. qla2x00_add_iodesc_timer(iodesc);
  345. /* Issue command to ISP. */
  346. qla2x00_isp_cmd(ha);
  347. if (!ha_locked)
  348. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  349. DEBUG14(printk("scsi(%ld): Sending Abort IOCB (%08x) to [%x], aborting "
  350. "%08x.\n", ha->host_no, iodesc->signature,
  351. iodesc->remote_fcport->loop_id, handle_to_abort));
  352. return (QLA_SUCCESS);
  353. }
  354. /**
  355. * qla2x00_send_abort_iocb_cb() - Abort IOCB callback.
  356. * @ha: HA context
  357. * @iodesc: io descriptor
  358. * @mbxstat: mailbox status IOCB
  359. *
  360. * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
  361. * will be used for a retry.
  362. */
  363. static int
  364. qla2x00_send_abort_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  365. struct mbx_entry *mbxstat)
  366. {
  367. DEBUG14(printk("scsi(%ld): Abort IOCB -- sent to [%x/%02x%02x%02x], "
  368. "status=%x mb0=%x.\n", ha->host_no, iodesc->remote_fcport->loop_id,
  369. iodesc->d_id.b.domain, iodesc->d_id.b.area, iodesc->d_id.b.al_pa,
  370. le16_to_cpu(mbxstat->status), le16_to_cpu(mbxstat->mb0)));
  371. return (QLA_SUCCESS);
  372. }
  373. /**
  374. * qla2x00_send_adisc_iocb() - Issue a Get Port Database IOCB to the firmware.
  375. * @ha: HA context
  376. * @iodesc: io descriptor
  377. * @ha_locked: is function called with the hardware lock
  378. *
  379. * Returns QLA_SUCCESS if the IOCB was issued.
  380. */
  381. static int
  382. qla2x00_send_adisc_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  383. int ha_locked)
  384. {
  385. unsigned long flags = 0;
  386. struct mbx_entry *mbxentry;
  387. /* Send marker if required. */
  388. if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
  389. return (QLA_FUNCTION_FAILED);
  390. if (!ha_locked)
  391. spin_lock_irqsave(&ha->hardware_lock, flags);
  392. /* Build Get Port Database IOCB. */
  393. mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
  394. if (mbxentry == NULL) {
  395. if (!ha_locked)
  396. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  397. return (QLA_FUNCTION_FAILED);
  398. }
  399. mbxentry->mb0 = __constant_cpu_to_le16(MBC_GET_PORT_DATABASE);
  400. mbxentry->mb1 = mbxentry->loop_id.extended =
  401. cpu_to_le16(iodesc->remote_fcport->loop_id);
  402. mbxentry->mb2 = cpu_to_le16(MSW(LSD(ha->iodesc_pd_dma)));
  403. mbxentry->mb3 = cpu_to_le16(LSW(LSD(ha->iodesc_pd_dma)));
  404. mbxentry->mb6 = cpu_to_le16(MSW(MSD(ha->iodesc_pd_dma)));
  405. mbxentry->mb7 = cpu_to_le16(LSW(MSD(ha->iodesc_pd_dma)));
  406. mbxentry->mb10 = __constant_cpu_to_le16(BIT_0);
  407. wmb();
  408. qla2x00_add_iodesc_timer(iodesc);
  409. /* Issue command to ISP. */
  410. qla2x00_isp_cmd(ha);
  411. if (!ha_locked)
  412. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  413. DEBUG14(printk("scsi(%ld): Sending Adisc IOCB (%08x) to [%x].\n",
  414. ha->host_no, iodesc->signature, iodesc->remote_fcport->loop_id));
  415. return (QLA_SUCCESS);
  416. }
  417. /**
  418. * qla2x00_send_adisc_iocb_cb() - Get Port Database IOCB callback.
  419. * @ha: HA context
  420. * @iodesc: io descriptor
  421. * @mbxstat: mailbox status IOCB
  422. *
  423. * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
  424. * will be used for a retry.
  425. */
  426. static int
  427. qla2x00_send_adisc_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  428. struct mbx_entry *mbxstat)
  429. {
  430. fc_port_t *remote_fcport;
  431. remote_fcport = iodesc->remote_fcport;
  432. /* Ensure the port IDs are consistent. */
  433. if (remote_fcport->d_id.b24 != iodesc->d_id.b24) {
  434. DEBUG14(printk("scsi(%ld): Adisc IOCB -- ignoring, remote port "
  435. "id changed from [%02x%02x%02x] to [%02x%02x%02x].\n",
  436. ha->host_no, remote_fcport->d_id.b.domain,
  437. remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa,
  438. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  439. iodesc->d_id.b.al_pa));
  440. return (QLA_SUCCESS);
  441. }
  442. /* Only process the last command. */
  443. if (remote_fcport->iodesc_idx_sent != iodesc->idx) {
  444. DEBUG14(printk("scsi(%ld): Adisc IOCB -- ignoring, sent to "
  445. "[%02x%02x%02x], expected %x, received %x.\n", ha->host_no,
  446. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  447. iodesc->d_id.b.al_pa, remote_fcport->iodesc_idx_sent,
  448. iodesc->idx));
  449. return (QLA_SUCCESS);
  450. }
  451. if (le16_to_cpu(mbxstat->status) == CS_COMPLETE) {
  452. DEBUG14(printk("scsi(%ld): Adisc IOCB -- marking "
  453. "[%x/%02x%02x%02x] online.\n", ha->host_no,
  454. remote_fcport->loop_id, remote_fcport->d_id.b.domain,
  455. remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa));
  456. atomic_set(&remote_fcport->state, FCS_ONLINE);
  457. } else {
  458. DEBUG14(printk("scsi(%ld): Adisc IOCB -- marking "
  459. "[%x/%02x%02x%02x] lost, status=%x mb0=%x.\n", ha->host_no,
  460. remote_fcport->loop_id, remote_fcport->d_id.b.domain,
  461. remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa,
  462. le16_to_cpu(mbxstat->status), le16_to_cpu(mbxstat->mb0)));
  463. if (atomic_read(&remote_fcport->state) != FCS_DEVICE_DEAD)
  464. atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
  465. }
  466. remote_fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
  467. return (QLA_SUCCESS);
  468. }
  469. /**
  470. * qla2x00_send_logout_iocb() - Issue a fabric port logout IOCB to the firmware.
  471. * @ha: HA context
  472. * @iodesc: io descriptor
  473. * @ha_locked: is function called with the hardware lock
  474. *
  475. * Returns QLA_SUCCESS if the IOCB was issued.
  476. */
  477. static int
  478. qla2x00_send_logout_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  479. int ha_locked)
  480. {
  481. unsigned long flags = 0;
  482. struct mbx_entry *mbxentry;
  483. /* Send marker if required. */
  484. if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
  485. return (QLA_FUNCTION_FAILED);
  486. if (!ha_locked)
  487. spin_lock_irqsave(&ha->hardware_lock, flags);
  488. /* Build fabric port logout mailbox IOCB. */
  489. mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
  490. if (mbxentry == NULL) {
  491. if (!ha_locked)
  492. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  493. return (QLA_FUNCTION_FAILED);
  494. }
  495. mbxentry->mb0 = __constant_cpu_to_le16(MBC_LOGOUT_FABRIC_PORT);
  496. mbxentry->mb1 = mbxentry->loop_id.extended =
  497. cpu_to_le16(iodesc->remote_fcport->loop_id);
  498. wmb();
  499. qla2x00_add_iodesc_timer(iodesc);
  500. /* Issue command to ISP. */
  501. qla2x00_isp_cmd(ha);
  502. if (!ha_locked)
  503. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  504. DEBUG14(printk("scsi(%ld): Sending Logout IOCB (%08x) to [%x].\n",
  505. ha->host_no, iodesc->signature, iodesc->remote_fcport->loop_id));
  506. return (QLA_SUCCESS);
  507. }
  508. /**
  509. * qla2x00_send_logout_iocb_cb() - Fabric port logout IOCB callback.
  510. * @ha: HA context
  511. * @iodesc: io descriptor
  512. * @mbxstat: mailbox status IOCB
  513. *
  514. * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
  515. * will be used for a retry.
  516. */
  517. static int
  518. qla2x00_send_logout_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  519. struct mbx_entry *mbxstat)
  520. {
  521. DEBUG14(printk("scsi(%ld): Logout IOCB -- sent to [%x/%02x%02x%02x], "
  522. "status=%x mb0=%x mb1=%x.\n", ha->host_no,
  523. iodesc->remote_fcport->loop_id,
  524. iodesc->remote_fcport->d_id.b.domain,
  525. iodesc->remote_fcport->d_id.b.area,
  526. iodesc->remote_fcport->d_id.b.al_pa, le16_to_cpu(mbxstat->status),
  527. le16_to_cpu(mbxstat->mb0), le16_to_cpu(mbxstat->mb1)));
  528. return (QLA_SUCCESS);
  529. }
  530. /**
  531. * qla2x00_send_login_iocb() - Issue a fabric port login IOCB to the firmware.
  532. * @ha: HA context
  533. * @iodesc: io descriptor
  534. * @d_id: port id for device
  535. * @ha_locked: is function called with the hardware lock
  536. *
  537. * Returns QLA_SUCCESS if the IOCB was issued.
  538. */
  539. static int
  540. qla2x00_send_login_iocb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  541. port_id_t *d_id, int ha_locked)
  542. {
  543. unsigned long flags = 0;
  544. struct mbx_entry *mbxentry;
  545. /* Send marker if required. */
  546. if (qla2x00_issue_marker(ha, ha_locked) != QLA_SUCCESS)
  547. return (QLA_FUNCTION_FAILED);
  548. if (!ha_locked)
  549. spin_lock_irqsave(&ha->hardware_lock, flags);
  550. /* Build fabric port login mailbox IOCB. */
  551. mbxentry = qla2x00_get_mbx_iocb_entry(ha, iodesc->signature);
  552. if (mbxentry == NULL) {
  553. if (!ha_locked)
  554. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  555. return (QLA_FUNCTION_FAILED);
  556. }
  557. mbxentry->mb0 = __constant_cpu_to_le16(MBC_LOGIN_FABRIC_PORT);
  558. mbxentry->mb1 = mbxentry->loop_id.extended =
  559. cpu_to_le16(iodesc->remote_fcport->loop_id);
  560. mbxentry->mb2 = cpu_to_le16(d_id->b.domain);
  561. mbxentry->mb3 = cpu_to_le16(d_id->b.area << 8 | d_id->b.al_pa);
  562. mbxentry->mb10 = __constant_cpu_to_le16(BIT_0);
  563. wmb();
  564. qla2x00_add_iodesc_timer(iodesc);
  565. /* Issue command to ISP. */
  566. qla2x00_isp_cmd(ha);
  567. if (!ha_locked)
  568. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  569. DEBUG14(printk("scsi(%ld): Sending Login IOCB (%08x) to "
  570. "[%x/%02x%02x%02x].\n", ha->host_no, iodesc->signature,
  571. iodesc->remote_fcport->loop_id, d_id->b.domain, d_id->b.area,
  572. d_id->b.al_pa));
  573. return (QLA_SUCCESS);
  574. }
  575. /**
  576. * qla2x00_send_login_iocb_cb() - Fabric port logout IOCB callback.
  577. * @ha: HA context
  578. * @iodesc: io descriptor
  579. * @mbxstat: mailbox status IOCB
  580. *
  581. * Returns QLA_SUCCESS if @iodesc can be freed by the caller, else, @iodesc
  582. * will be used for a retry.
  583. */
  584. static int
  585. qla2x00_send_login_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
  586. struct mbx_entry *mbxstat)
  587. {
  588. int rval;
  589. fc_port_t *fcport, *remote_fcport, *exist_fcport;
  590. struct io_descriptor *abort_iodesc, *login_iodesc;
  591. uint16_t status, mb[8];
  592. uint16_t reuse;
  593. uint16_t remote_loopid;
  594. port_id_t remote_did, inuse_did;
  595. remote_fcport = iodesc->remote_fcport;
  596. /* Only process the last command. */
  597. if (remote_fcport->iodesc_idx_sent != iodesc->idx) {
  598. DEBUG14(printk("scsi(%ld): Login IOCB -- ignoring, sent to "
  599. "[%02x%02x%02x], expected %x, received %x.\n",
  600. ha->host_no, iodesc->d_id.b.domain, iodesc->d_id.b.area,
  601. iodesc->d_id.b.al_pa, remote_fcport->iodesc_idx_sent,
  602. iodesc->idx));
  603. /* Free RSCN fcport resources. */
  604. if (remote_fcport->port_type == FCT_RSCN) {
  605. DEBUG14(printk("scsi(%ld): Login IOCB -- Freeing RSCN "
  606. "fcport %p [%x/%02x%02x%02x] given ignored Login "
  607. "IOCB.\n", ha->host_no, remote_fcport,
  608. remote_fcport->loop_id,
  609. remote_fcport->d_id.b.domain,
  610. remote_fcport->d_id.b.area,
  611. remote_fcport->d_id.b.al_pa));
  612. list_del(&remote_fcport->list);
  613. kfree(remote_fcport);
  614. }
  615. return (QLA_SUCCESS);
  616. }
  617. status = le16_to_cpu(mbxstat->status);
  618. mb[0] = le16_to_cpu(mbxstat->mb0);
  619. mb[1] = le16_to_cpu(mbxstat->mb1);
  620. mb[2] = le16_to_cpu(mbxstat->mb2);
  621. mb[6] = le16_to_cpu(mbxstat->mb6);
  622. mb[7] = le16_to_cpu(mbxstat->mb7);
  623. /* Good status? */
  624. if ((status == CS_COMPLETE || status == CS_COMPLETE_CHKCOND) &&
  625. mb[0] == MBS_COMMAND_COMPLETE) {
  626. DEBUG14(printk("scsi(%ld): Login IOCB -- status=%x mb1=%x pn="
  627. "%02x%02x%02x%02x%02x%02x%02x%02x.\n", ha->host_no, status,
  628. mb[1], mbxstat->port_name[0], mbxstat->port_name[1],
  629. mbxstat->port_name[2], mbxstat->port_name[3],
  630. mbxstat->port_name[4], mbxstat->port_name[5],
  631. mbxstat->port_name[6], mbxstat->port_name[7]));
  632. memcpy(remote_fcport->node_name, mbxstat->node_name, WWN_SIZE);
  633. memcpy(remote_fcport->port_name, mbxstat->port_name, WWN_SIZE);
  634. /* Is the device already in our fcports list? */
  635. if (remote_fcport->port_type != FCT_RSCN) {
  636. DEBUG14(printk("scsi(%ld): Login IOCB -- marking "
  637. "[%x/%02x%02x%02x] online.\n", ha->host_no,
  638. remote_fcport->loop_id,
  639. remote_fcport->d_id.b.domain,
  640. remote_fcport->d_id.b.area,
  641. remote_fcport->d_id.b.al_pa));
  642. qla2x00_update_login_fcport(ha, mbxstat, remote_fcport);
  643. return (QLA_SUCCESS);
  644. }
  645. /* Does the RSCN portname already exist in our fcports list? */
  646. exist_fcport = NULL;
  647. list_for_each_entry(fcport, &ha->fcports, list) {
  648. if (memcmp(remote_fcport->port_name, fcport->port_name,
  649. WWN_SIZE) == 0) {
  650. exist_fcport = fcport;
  651. break;
  652. }
  653. }
  654. if (exist_fcport != NULL) {
  655. DEBUG14(printk("scsi(%ld): Login IOCB -- found RSCN "
  656. "fcport in fcports list [%p].\n", ha->host_no,
  657. exist_fcport));
  658. /* Abort any ADISC that could have been sent. */
  659. if (exist_fcport->iodesc_idx_sent != iodesc->idx &&
  660. exist_fcport->iodesc_idx_sent <
  661. MAX_IO_DESCRIPTORS &&
  662. ha->io_descriptors[exist_fcport->iodesc_idx_sent].
  663. cb_idx == ADISC_PORT_IOCB_CB) {
  664. abort_iodesc = qla2x00_alloc_iodesc(ha);
  665. if (abort_iodesc) {
  666. DEBUG14(printk("scsi(%ld): Login IOCB "
  667. "-- issuing abort to outstanding "
  668. "Adisc [%x/%02x%02x%02x].\n",
  669. ha->host_no, remote_fcport->loop_id,
  670. exist_fcport->d_id.b.domain,
  671. exist_fcport->d_id.b.area,
  672. exist_fcport->d_id.b.al_pa));
  673. abort_iodesc->cb_idx = ABORT_IOCB_CB;
  674. abort_iodesc->d_id.b24 =
  675. exist_fcport->d_id.b24;
  676. abort_iodesc->remote_fcport =
  677. exist_fcport;
  678. exist_fcport->iodesc_idx_sent =
  679. abort_iodesc->idx;
  680. qla2x00_send_abort_iocb(ha,
  681. abort_iodesc, ha->io_descriptors[
  682. exist_fcport->iodesc_idx_sent].
  683. signature, 1);
  684. } else {
  685. DEBUG14(printk("scsi(%ld): Login IOCB "
  686. "-- unable to abort outstanding "
  687. "Adisc [%x/%02x%02x%02x].\n",
  688. ha->host_no, remote_fcport->loop_id,
  689. exist_fcport->d_id.b.domain,
  690. exist_fcport->d_id.b.area,
  691. exist_fcport->d_id.b.al_pa));
  692. }
  693. }
  694. /*
  695. * If the existing fcport is waiting to send an ADISC
  696. * or LOGIN, then reuse remote fcport (RSCN) to
  697. * continue waiting.
  698. */
  699. reuse = 0;
  700. remote_loopid = remote_fcport->loop_id;
  701. remote_did.b24 = remote_fcport->d_id.b24;
  702. if (exist_fcport->iodesc_idx_sent ==
  703. IODESC_ADISC_NEEDED ||
  704. exist_fcport->iodesc_idx_sent ==
  705. IODESC_LOGIN_NEEDED) {
  706. DEBUG14(printk("scsi(%ld): Login IOCB -- "
  707. "existing fcport [%x/%02x%02x%02x] "
  708. "waiting for IO descriptor, reuse RSCN "
  709. "fcport.\n", ha->host_no,
  710. exist_fcport->loop_id,
  711. exist_fcport->d_id.b.domain,
  712. exist_fcport->d_id.b.area,
  713. exist_fcport->d_id.b.al_pa));
  714. reuse++;
  715. remote_fcport->iodesc_idx_sent =
  716. exist_fcport->iodesc_idx_sent;
  717. exist_fcport->iodesc_idx_sent =
  718. IODESC_INVALID_INDEX;
  719. remote_fcport->loop_id = exist_fcport->loop_id;
  720. remote_fcport->d_id.b24 =
  721. exist_fcport->d_id.b24;
  722. }
  723. /* Logout the old loopid. */
  724. if (!reuse &&
  725. exist_fcport->loop_id != remote_fcport->loop_id &&
  726. exist_fcport->loop_id != FC_NO_LOOP_ID) {
  727. login_iodesc = qla2x00_alloc_iodesc(ha);
  728. if (login_iodesc) {
  729. DEBUG14(printk("scsi(%ld): Login IOCB "
  730. "-- issuing logout to free old "
  731. "loop id [%x/%02x%02x%02x].\n",
  732. ha->host_no, exist_fcport->loop_id,
  733. exist_fcport->d_id.b.domain,
  734. exist_fcport->d_id.b.area,
  735. exist_fcport->d_id.b.al_pa));
  736. login_iodesc->cb_idx =
  737. LOGOUT_PORT_IOCB_CB;
  738. login_iodesc->d_id.b24 =
  739. exist_fcport->d_id.b24;
  740. login_iodesc->remote_fcport =
  741. exist_fcport;
  742. exist_fcport->iodesc_idx_sent =
  743. login_iodesc->idx;
  744. qla2x00_send_logout_iocb(ha,
  745. login_iodesc, 1);
  746. } else {
  747. /* Ran out of IO descriptiors. */
  748. DEBUG14(printk("scsi(%ld): Login IOCB "
  749. "-- unable to logout to free old "
  750. "loop id [%x/%02x%02x%02x].\n",
  751. ha->host_no, exist_fcport->loop_id,
  752. exist_fcport->d_id.b.domain,
  753. exist_fcport->d_id.b.area,
  754. exist_fcport->d_id.b.al_pa));
  755. exist_fcport->iodesc_idx_sent =
  756. IODESC_INVALID_INDEX;
  757. }
  758. }
  759. /* Update existing fcport with remote fcport info. */
  760. DEBUG14(printk("scsi(%ld): Login IOCB -- marking "
  761. "existing fcport [%x/%02x%02x%02x] online.\n",
  762. ha->host_no, remote_loopid, remote_did.b.domain,
  763. remote_did.b.area, remote_did.b.al_pa));
  764. memcpy(exist_fcport->node_name,
  765. remote_fcport->node_name, WWN_SIZE);
  766. exist_fcport->loop_id = remote_loopid;
  767. exist_fcport->d_id.b24 = remote_did.b24;
  768. qla2x00_update_login_fcport(ha, mbxstat, exist_fcport);
  769. /* Finally, free the remote (RSCN) fcport. */
  770. if (!reuse) {
  771. DEBUG14(printk("scsi(%ld): Login IOCB -- "
  772. "Freeing RSCN fcport %p "
  773. "[%x/%02x%02x%02x].\n", ha->host_no,
  774. remote_fcport, remote_fcport->loop_id,
  775. remote_fcport->d_id.b.domain,
  776. remote_fcport->d_id.b.area,
  777. remote_fcport->d_id.b.al_pa));
  778. list_del(&remote_fcport->list);
  779. kfree(remote_fcport);
  780. }
  781. return (QLA_SUCCESS);
  782. }
  783. /*
  784. * A new device has been added, move the RSCN fcport to our
  785. * fcports list.
  786. */
  787. DEBUG14(printk("scsi(%ld): Login IOCB -- adding RSCN fcport "
  788. "[%x/%02x%02x%02x] to fcports list.\n", ha->host_no,
  789. remote_fcport->loop_id, remote_fcport->d_id.b.domain,
  790. remote_fcport->d_id.b.area, remote_fcport->d_id.b.al_pa));
  791. list_del(&remote_fcport->list);
  792. remote_fcport->flags = (FCF_RLC_SUPPORT | FCF_RESCAN_NEEDED);
  793. qla2x00_update_login_fcport(ha, mbxstat, remote_fcport);
  794. list_add_tail(&remote_fcport->list, &ha->fcports);
  795. set_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags);
  796. } else {
  797. /* Handle login failure. */
  798. if (remote_fcport->login_retry != 0) {
  799. if (mb[0] == MBS_LOOP_ID_USED) {
  800. inuse_did.b.domain = LSB(mb[1]);
  801. inuse_did.b.area = MSB(mb[2]);
  802. inuse_did.b.al_pa = LSB(mb[2]);
  803. DEBUG14(printk("scsi(%ld): Login IOCB -- loop "
  804. "id [%x] used by port id [%02x%02x%02x].\n",
  805. ha->host_no, remote_fcport->loop_id,
  806. inuse_did.b.domain, inuse_did.b.area,
  807. inuse_did.b.al_pa));
  808. if (remote_fcport->d_id.b24 ==
  809. INVALID_PORT_ID) {
  810. /*
  811. * Invalid port id means we are trying
  812. * to login to a remote port with just
  813. * a loop id without knowing about the
  814. * port id. Copy the port id and try
  815. * again.
  816. */
  817. remote_fcport->d_id.b24 = inuse_did.b24;
  818. iodesc->d_id.b24 = inuse_did.b24;
  819. } else {
  820. remote_fcport->loop_id++;
  821. rval = qla2x00_find_new_loop_id(ha,
  822. remote_fcport);
  823. if (rval == QLA_FUNCTION_FAILED) {
  824. /* No more loop ids. */
  825. return (QLA_SUCCESS);
  826. }
  827. }
  828. } else if (mb[0] == MBS_PORT_ID_USED) {
  829. /*
  830. * Device has another loop ID. The firmware
  831. * group recommends the driver perform an
  832. * implicit login with the specified ID.
  833. */
  834. DEBUG14(printk("scsi(%ld): Login IOCB -- port "
  835. "id [%02x%02x%02x] already assigned to "
  836. "loop id [%x].\n", ha->host_no,
  837. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  838. iodesc->d_id.b.al_pa, mb[1]));
  839. remote_fcport->loop_id = mb[1];
  840. } else {
  841. /* Unable to perform login, try again. */
  842. DEBUG14(printk("scsi(%ld): Login IOCB -- "
  843. "failed login [%x/%02x%02x%02x], status=%x "
  844. "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n",
  845. ha->host_no, remote_fcport->loop_id,
  846. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  847. iodesc->d_id.b.al_pa, status, mb[0], mb[1],
  848. mb[2], mb[6], mb[7]));
  849. }
  850. /* Reissue Login with the same IO descriptor. */
  851. iodesc->signature =
  852. qla2x00_iodesc_to_handle(iodesc);
  853. iodesc->cb_idx = LOGIN_PORT_IOCB_CB;
  854. iodesc->d_id.b24 = remote_fcport->d_id.b24;
  855. remote_fcport->iodesc_idx_sent = iodesc->idx;
  856. remote_fcport->login_retry--;
  857. DEBUG14(printk("scsi(%ld): Login IOCB -- retrying "
  858. "login to [%x/%02x%02x%02x] (%d).\n", ha->host_no,
  859. remote_fcport->loop_id,
  860. remote_fcport->d_id.b.domain,
  861. remote_fcport->d_id.b.area,
  862. remote_fcport->d_id.b.al_pa,
  863. remote_fcport->login_retry));
  864. qla2x00_send_login_iocb(ha, iodesc,
  865. &remote_fcport->d_id, 1);
  866. return (QLA_FUNCTION_FAILED);
  867. } else {
  868. /* No more logins, mark device dead. */
  869. DEBUG14(printk("scsi(%ld): Login IOCB -- failed "
  870. "login [%x/%02x%02x%02x] after retries, status=%x "
  871. "mb0=%x mb1=%x mb2=%x mb6=%x mb7=%x.\n",
  872. ha->host_no, remote_fcport->loop_id,
  873. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  874. iodesc->d_id.b.al_pa, status, mb[0], mb[1],
  875. mb[2], mb[6], mb[7]));
  876. atomic_set(&remote_fcport->state, FCS_DEVICE_DEAD);
  877. if (remote_fcport->port_type == FCT_RSCN) {
  878. DEBUG14(printk("scsi(%ld): Login IOCB -- "
  879. "Freeing dead RSCN fcport %p "
  880. "[%x/%02x%02x%02x].\n", ha->host_no,
  881. remote_fcport, remote_fcport->loop_id,
  882. remote_fcport->d_id.b.domain,
  883. remote_fcport->d_id.b.area,
  884. remote_fcport->d_id.b.al_pa));
  885. list_del(&remote_fcport->list);
  886. kfree(remote_fcport);
  887. }
  888. }
  889. }
  890. return (QLA_SUCCESS);
  891. }
  892. /**
  893. * IO descriptor processing routines.
  894. **/
  895. /**
  896. * qla2x00_alloc_rscn_fcport() - Allocate an RSCN type fcport.
  897. * @ha: HA context
  898. * @flags: allocation flags
  899. *
  900. * Returns a pointer to the allocated RSCN fcport, or NULL, if none available.
  901. */
  902. fc_port_t *
  903. qla2x00_alloc_rscn_fcport(scsi_qla_host_t *ha, gfp_t flags)
  904. {
  905. fc_port_t *fcport;
  906. fcport = qla2x00_alloc_fcport(ha, flags);
  907. if (fcport == NULL)
  908. return (fcport);
  909. /* Setup RSCN fcport structure. */
  910. fcport->port_type = FCT_RSCN;
  911. return (fcport);
  912. }
  913. /**
  914. * qla2x00_handle_port_rscn() - Handle port RSCN.
  915. * @ha: HA context
  916. * @rscn_entry: RSCN entry
  917. * @fcport: fcport entry to updated
  918. *
  919. * Returns QLA_SUCCESS if the port RSCN was handled.
  920. */
  921. int
  922. qla2x00_handle_port_rscn(scsi_qla_host_t *ha, uint32_t rscn_entry,
  923. fc_port_t *known_fcport, int ha_locked)
  924. {
  925. int rval;
  926. port_id_t rscn_pid;
  927. fc_port_t *fcport, *remote_fcport, *rscn_fcport;
  928. struct io_descriptor *iodesc;
  929. remote_fcport = NULL;
  930. rscn_fcport = NULL;
  931. /* Prepare port id based on incoming entries. */
  932. if (known_fcport) {
  933. rscn_pid.b24 = known_fcport->d_id.b24;
  934. remote_fcport = known_fcport;
  935. DEBUG14(printk("scsi(%ld): Handle RSCN -- process RSCN for "
  936. "fcport [%02x%02x%02x].\n", ha->host_no,
  937. remote_fcport->d_id.b.domain, remote_fcport->d_id.b.area,
  938. remote_fcport->d_id.b.al_pa));
  939. } else {
  940. rscn_pid.b.domain = LSB(MSW(rscn_entry));
  941. rscn_pid.b.area = MSB(LSW(rscn_entry));
  942. rscn_pid.b.al_pa = LSB(LSW(rscn_entry));
  943. DEBUG14(printk("scsi(%ld): Handle RSCN -- process RSCN for "
  944. "port id [%02x%02x%02x].\n", ha->host_no,
  945. rscn_pid.b.domain, rscn_pid.b.area, rscn_pid.b.al_pa));
  946. /*
  947. * Search fcport lists for a known entry at the specified port
  948. * ID.
  949. */
  950. list_for_each_entry(fcport, &ha->fcports, list) {
  951. if (rscn_pid.b24 == fcport->d_id.b24) {
  952. remote_fcport = fcport;
  953. break;
  954. }
  955. }
  956. list_for_each_entry(fcport, &ha->rscn_fcports, list) {
  957. if (rscn_pid.b24 == fcport->d_id.b24) {
  958. rscn_fcport = fcport;
  959. break;
  960. }
  961. }
  962. if (remote_fcport == NULL)
  963. remote_fcport = rscn_fcport;
  964. }
  965. /*
  966. * If the port is already in our fcport list and online, send an ADISC
  967. * to see if it's still alive. Issue login if a new fcport or the known
  968. * fcport is currently offline.
  969. */
  970. if (remote_fcport) {
  971. /*
  972. * No need to send request if the remote fcport is currently
  973. * waiting for an available io descriptor.
  974. */
  975. if (known_fcport == NULL &&
  976. (remote_fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
  977. remote_fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED)) {
  978. /*
  979. * If previous waiting io descriptor is an ADISC, then
  980. * the new RSCN may come from a new remote fcport being
  981. * plugged into the same location.
  982. */
  983. if (remote_fcport->port_type == FCT_RSCN) {
  984. remote_fcport->iodesc_idx_sent =
  985. IODESC_LOGIN_NEEDED;
  986. } else if (remote_fcport->iodesc_idx_sent ==
  987. IODESC_ADISC_NEEDED) {
  988. fc_port_t *new_fcport;
  989. remote_fcport->iodesc_idx_sent =
  990. IODESC_INVALID_INDEX;
  991. /* Create new fcport for later login. */
  992. new_fcport = qla2x00_alloc_rscn_fcport(ha,
  993. ha_locked ? GFP_ATOMIC: GFP_KERNEL);
  994. if (new_fcport) {
  995. DEBUG14(printk("scsi(%ld): Handle RSCN "
  996. "-- creating RSCN fcport %p for "
  997. "future login.\n", ha->host_no,
  998. new_fcport));
  999. new_fcport->d_id.b24 =
  1000. remote_fcport->d_id.b24;
  1001. new_fcport->iodesc_idx_sent =
  1002. IODESC_LOGIN_NEEDED;
  1003. list_add_tail(&new_fcport->list,
  1004. &ha->rscn_fcports);
  1005. set_bit(IODESC_PROCESS_NEEDED,
  1006. &ha->dpc_flags);
  1007. } else {
  1008. DEBUG14(printk("scsi(%ld): Handle RSCN "
  1009. "-- unable to allocate RSCN fcport "
  1010. "for future login.\n",
  1011. ha->host_no));
  1012. }
  1013. }
  1014. return (QLA_SUCCESS);
  1015. }
  1016. /* Send ADISC if the fcport is online */
  1017. if (atomic_read(&remote_fcport->state) == FCS_ONLINE ||
  1018. remote_fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED) {
  1019. atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
  1020. iodesc = qla2x00_alloc_iodesc(ha);
  1021. if (iodesc == NULL) {
  1022. /* Mark fcport for later adisc processing */
  1023. DEBUG14(printk("scsi(%ld): Handle RSCN -- not "
  1024. "enough IO descriptors for Adisc, flag "
  1025. "for later processing.\n", ha->host_no));
  1026. remote_fcport->iodesc_idx_sent =
  1027. IODESC_ADISC_NEEDED;
  1028. set_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
  1029. return (QLA_SUCCESS);
  1030. }
  1031. iodesc->cb_idx = ADISC_PORT_IOCB_CB;
  1032. iodesc->d_id.b24 = rscn_pid.b24;
  1033. iodesc->remote_fcport = remote_fcport;
  1034. remote_fcport->iodesc_idx_sent = iodesc->idx;
  1035. qla2x00_send_adisc_iocb(ha, iodesc, ha_locked);
  1036. return (QLA_SUCCESS);
  1037. } else if (remote_fcport->iodesc_idx_sent <
  1038. MAX_IO_DESCRIPTORS &&
  1039. ha->io_descriptors[remote_fcport->iodesc_idx_sent].cb_idx ==
  1040. ADISC_PORT_IOCB_CB) {
  1041. /*
  1042. * Receiving another RSCN while an ADISC is pending,
  1043. * abort the IOCB. Use the same descriptor for the
  1044. * abort.
  1045. */
  1046. uint32_t handle_to_abort;
  1047. iodesc = &ha->io_descriptors[
  1048. remote_fcport->iodesc_idx_sent];
  1049. qla2x00_remove_iodesc_timer(iodesc);
  1050. handle_to_abort = iodesc->signature;
  1051. iodesc->signature = qla2x00_iodesc_to_handle(iodesc);
  1052. iodesc->cb_idx = ABORT_IOCB_CB;
  1053. iodesc->d_id.b24 = remote_fcport->d_id.b24;
  1054. iodesc->remote_fcport = remote_fcport;
  1055. remote_fcport->iodesc_idx_sent = iodesc->idx;
  1056. DEBUG14(printk("scsi(%ld): Handle RSCN -- issuing "
  1057. "abort to outstanding Adisc [%x/%02x%02x%02x].\n",
  1058. ha->host_no, remote_fcport->loop_id,
  1059. iodesc->d_id.b.domain, iodesc->d_id.b.area,
  1060. iodesc->d_id.b.al_pa));
  1061. qla2x00_send_abort_iocb(ha, iodesc, handle_to_abort,
  1062. ha_locked);
  1063. }
  1064. }
  1065. /* We need to login to the remote port, find it. */
  1066. if (known_fcport) {
  1067. remote_fcport = known_fcport;
  1068. } else if (rscn_fcport && rscn_fcport->d_id.b24 != INVALID_PORT_ID &&
  1069. rscn_fcport->iodesc_idx_sent < MAX_IO_DESCRIPTORS &&
  1070. ha->io_descriptors[rscn_fcport->iodesc_idx_sent].cb_idx ==
  1071. LOGIN_PORT_IOCB_CB) {
  1072. /*
  1073. * Ignore duplicate RSCN on fcport which has already
  1074. * initiated a login IOCB.
  1075. */
  1076. DEBUG14(printk("scsi(%ld): Handle RSCN -- ignoring, login "
  1077. "already sent to [%02x%02x%02x].\n", ha->host_no,
  1078. rscn_fcport->d_id.b.domain, rscn_fcport->d_id.b.area,
  1079. rscn_fcport->d_id.b.al_pa));
  1080. return (QLA_SUCCESS);
  1081. } else if (rscn_fcport && rscn_fcport->d_id.b24 != INVALID_PORT_ID &&
  1082. rscn_fcport != remote_fcport) {
  1083. /* Reuse same rscn fcport. */
  1084. DEBUG14(printk("scsi(%ld): Handle RSCN -- reusing RSCN fcport "
  1085. "[%02x%02x%02x].\n", ha->host_no,
  1086. rscn_fcport->d_id.b.domain, rscn_fcport->d_id.b.area,
  1087. rscn_fcport->d_id.b.al_pa));
  1088. remote_fcport = rscn_fcport;
  1089. } else {
  1090. /* Create new fcport for later login. */
  1091. remote_fcport = qla2x00_alloc_rscn_fcport(ha,
  1092. ha_locked ? GFP_ATOMIC: GFP_KERNEL);
  1093. list_add_tail(&remote_fcport->list, &ha->rscn_fcports);
  1094. }
  1095. if (remote_fcport == NULL)
  1096. return (QLA_SUCCESS);
  1097. /* Prepare fcport for login. */
  1098. atomic_set(&remote_fcport->state, FCS_DEVICE_LOST);
  1099. remote_fcport->login_retry = 3; /* ha->login_retry_count; */
  1100. remote_fcport->d_id.b24 = rscn_pid.b24;
  1101. iodesc = qla2x00_alloc_iodesc(ha);
  1102. if (iodesc == NULL) {
  1103. /* Mark fcport for later adisc processing. */
  1104. DEBUG14(printk("scsi(%ld): Handle RSCN -- not enough IO "
  1105. "descriptors for Login, flag for later processing.\n",
  1106. ha->host_no));
  1107. remote_fcport->iodesc_idx_sent = IODESC_LOGIN_NEEDED;
  1108. set_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
  1109. return (QLA_SUCCESS);
  1110. }
  1111. if (known_fcport == NULL || rscn_pid.b24 != INVALID_PORT_ID) {
  1112. remote_fcport->loop_id = ha->min_external_loopid;
  1113. rval = qla2x00_find_new_loop_id(ha, remote_fcport);
  1114. if (rval == QLA_FUNCTION_FAILED) {
  1115. /* No more loop ids, failed. */
  1116. DEBUG14(printk("scsi(%ld): Handle RSCN -- no available "
  1117. "loop id to perform Login, failed.\n",
  1118. ha->host_no));
  1119. return (rval);
  1120. }
  1121. }
  1122. iodesc->cb_idx = LOGIN_PORT_IOCB_CB;
  1123. iodesc->d_id.b24 = rscn_pid.b24;
  1124. iodesc->remote_fcport = remote_fcport;
  1125. remote_fcport->iodesc_idx_sent = iodesc->idx;
  1126. DEBUG14(printk("scsi(%ld): Handle RSCN -- attempting login to "
  1127. "[%x/%02x%02x%02x].\n", ha->host_no, remote_fcport->loop_id,
  1128. iodesc->d_id.b.domain, iodesc->d_id.b.area, iodesc->d_id.b.al_pa));
  1129. qla2x00_send_login_iocb(ha, iodesc, &rscn_pid, ha_locked);
  1130. return (QLA_SUCCESS);
  1131. }
  1132. /**
  1133. * qla2x00_process_iodesc() - Complete IO descriptor processing.
  1134. * @ha: HA context
  1135. * @mbxstat: Mailbox IOCB status
  1136. */
  1137. void
  1138. qla2x00_process_iodesc(scsi_qla_host_t *ha, struct mbx_entry *mbxstat)
  1139. {
  1140. int rval;
  1141. uint32_t signature;
  1142. fc_port_t *fcport;
  1143. struct io_descriptor *iodesc;
  1144. signature = mbxstat->handle;
  1145. DEBUG14(printk("scsi(%ld): Process IODesc -- processing %08x.\n",
  1146. ha->host_no, signature));
  1147. /* Retrieve proper IO descriptor. */
  1148. iodesc = qla2x00_handle_to_iodesc(ha, signature);
  1149. if (iodesc == NULL) {
  1150. DEBUG14(printk("scsi(%ld): Process IODesc -- ignoring, "
  1151. "incorrect signature %08x.\n", ha->host_no, signature));
  1152. return;
  1153. }
  1154. /* Stop IO descriptor timer. */
  1155. qla2x00_remove_iodesc_timer(iodesc);
  1156. /* Verify signature match. */
  1157. if (iodesc->signature != signature) {
  1158. DEBUG14(printk("scsi(%ld): Process IODesc -- ignoring, "
  1159. "signature mismatch, sent %08x, received %08x.\n",
  1160. ha->host_no, iodesc->signature, signature));
  1161. return;
  1162. }
  1163. /* Go with IOCB callback. */
  1164. rval = iocb_function_cb_list[iodesc->cb_idx](ha, iodesc, mbxstat);
  1165. if (rval != QLA_SUCCESS) {
  1166. /* IO descriptor reused by callback. */
  1167. return;
  1168. }
  1169. qla2x00_free_iodesc(iodesc);
  1170. if (test_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags)) {
  1171. /* Scan our fcports list for any RSCN requests. */
  1172. list_for_each_entry(fcport, &ha->fcports, list) {
  1173. if (fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
  1174. fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED) {
  1175. qla2x00_handle_port_rscn(ha, 0, fcport, 1);
  1176. return;
  1177. }
  1178. }
  1179. /* Scan our RSCN fcports list for any RSCN requests. */
  1180. list_for_each_entry(fcport, &ha->rscn_fcports, list) {
  1181. if (fcport->iodesc_idx_sent == IODESC_ADISC_NEEDED ||
  1182. fcport->iodesc_idx_sent == IODESC_LOGIN_NEEDED) {
  1183. qla2x00_handle_port_rscn(ha, 0, fcport, 1);
  1184. return;
  1185. }
  1186. }
  1187. }
  1188. clear_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
  1189. }
  1190. /**
  1191. * qla2x00_cancel_io_descriptors() - Cancel all outstanding io descriptors.
  1192. * @ha: HA context
  1193. *
  1194. * This routine will also delete any RSCN entries related to the outstanding
  1195. * IO descriptors.
  1196. */
  1197. void
  1198. qla2x00_cancel_io_descriptors(scsi_qla_host_t *ha)
  1199. {
  1200. fc_port_t *fcport, *fcptemp;
  1201. clear_bit(IODESC_PROCESS_NEEDED, &ha->dpc_flags);
  1202. /* Abort all IO descriptors. */
  1203. qla2x00_init_io_descriptors(ha);
  1204. /* Reset all pending IO descriptors in fcports list. */
  1205. list_for_each_entry(fcport, &ha->fcports, list) {
  1206. fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
  1207. }
  1208. /* Reset all pending IO descriptors in rscn fcports list. */
  1209. list_for_each_entry_safe(fcport, fcptemp, &ha->rscn_fcports, list) {
  1210. DEBUG14(printk("scsi(%ld): Cancel IOs -- Freeing RSCN fcport "
  1211. "%p [%x/%02x%02x%02x].\n", ha->host_no, fcport,
  1212. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1213. fcport->d_id.b.al_pa));
  1214. list_del(&fcport->list);
  1215. kfree(fcport);
  1216. }
  1217. }