qla_rscn.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  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. if (fcport->rport)
  275. fc_remote_port_unblock(fcport->rport);
  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. }