fc_lport.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781
  1. /*
  2. * Copyright(c) 2007 Intel Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * Maintained at www.Open-FCoE.org
  18. */
  19. /*
  20. * PORT LOCKING NOTES
  21. *
  22. * These comments only apply to the 'port code' which consists of the lport,
  23. * disc and rport blocks.
  24. *
  25. * MOTIVATION
  26. *
  27. * The lport, disc and rport blocks all have mutexes that are used to protect
  28. * those objects. The main motivation for these locks is to prevent from
  29. * having an lport reset just before we send a frame. In that scenario the
  30. * lport's FID would get set to zero and then we'd send a frame with an
  31. * invalid SID. We also need to ensure that states don't change unexpectedly
  32. * while processing another state.
  33. *
  34. * HEIRARCHY
  35. *
  36. * The following heirarchy defines the locking rules. A greater lock
  37. * may be held before acquiring a lesser lock, but a lesser lock should never
  38. * be held while attempting to acquire a greater lock. Here is the heirarchy-
  39. *
  40. * lport > disc, lport > rport, disc > rport
  41. *
  42. * CALLBACKS
  43. *
  44. * The callbacks cause complications with this scheme. There is a callback
  45. * from the rport (to either lport or disc) and a callback from disc
  46. * (to the lport).
  47. *
  48. * As rports exit the rport state machine a callback is made to the owner of
  49. * the rport to notify success or failure. Since the callback is likely to
  50. * cause the lport or disc to grab its lock we cannot hold the rport lock
  51. * while making the callback. To ensure that the rport is not free'd while
  52. * processing the callback the rport callbacks are serialized through a
  53. * single-threaded workqueue. An rport would never be free'd while in a
  54. * callback handler becuase no other rport work in this queue can be executed
  55. * at the same time.
  56. *
  57. * When discovery succeeds or fails a callback is made to the lport as
  58. * notification. Currently, succesful discovery causes the lport to take no
  59. * action. A failure will cause the lport to reset. There is likely a circular
  60. * locking problem with this implementation.
  61. */
  62. /*
  63. * LPORT LOCKING
  64. *
  65. * The critical sections protected by the lport's mutex are quite broad and
  66. * may be improved upon in the future. The lport code and its locking doesn't
  67. * influence the I/O path, so excessive locking doesn't penalize I/O
  68. * performance.
  69. *
  70. * The strategy is to lock whenever processing a request or response. Note
  71. * that every _enter_* function corresponds to a state change. They generally
  72. * change the lports state and then send a request out on the wire. We lock
  73. * before calling any of these functions to protect that state change. This
  74. * means that the entry points into the lport block manage the locks while
  75. * the state machine can transition between states (i.e. _enter_* functions)
  76. * while always staying protected.
  77. *
  78. * When handling responses we also hold the lport mutex broadly. When the
  79. * lport receives the response frame it locks the mutex and then calls the
  80. * appropriate handler for the particuar response. Generally a response will
  81. * trigger a state change and so the lock must already be held.
  82. *
  83. * Retries also have to consider the locking. The retries occur from a work
  84. * context and the work function will lock the lport and then retry the state
  85. * (i.e. _enter_* function).
  86. */
  87. #include <linux/timer.h>
  88. #include <asm/unaligned.h>
  89. #include <scsi/fc/fc_gs.h>
  90. #include <scsi/libfc.h>
  91. #include <scsi/fc_encode.h>
  92. #include <linux/scatterlist.h>
  93. #include "fc_libfc.h"
  94. /* Fabric IDs to use for point-to-point mode, chosen on whims. */
  95. #define FC_LOCAL_PTP_FID_LO 0x010101
  96. #define FC_LOCAL_PTP_FID_HI 0x010102
  97. #define DNS_DELAY 3 /* Discovery delay after RSCN (in seconds)*/
  98. static void fc_lport_error(struct fc_lport *, struct fc_frame *);
  99. static void fc_lport_enter_reset(struct fc_lport *);
  100. static void fc_lport_enter_flogi(struct fc_lport *);
  101. static void fc_lport_enter_dns(struct fc_lport *);
  102. static void fc_lport_enter_ns(struct fc_lport *, enum fc_lport_state);
  103. static void fc_lport_enter_scr(struct fc_lport *);
  104. static void fc_lport_enter_ready(struct fc_lport *);
  105. static void fc_lport_enter_logo(struct fc_lport *);
  106. static const char *fc_lport_state_names[] = {
  107. [LPORT_ST_DISABLED] = "disabled",
  108. [LPORT_ST_FLOGI] = "FLOGI",
  109. [LPORT_ST_DNS] = "dNS",
  110. [LPORT_ST_RNN_ID] = "RNN_ID",
  111. [LPORT_ST_RSNN_NN] = "RSNN_NN",
  112. [LPORT_ST_RSPN_ID] = "RSPN_ID",
  113. [LPORT_ST_RFT_ID] = "RFT_ID",
  114. [LPORT_ST_SCR] = "SCR",
  115. [LPORT_ST_READY] = "Ready",
  116. [LPORT_ST_LOGO] = "LOGO",
  117. [LPORT_ST_RESET] = "reset",
  118. };
  119. /**
  120. * struct fc_bsg_info - FC Passthrough managemet structure
  121. * @job: The passthrough job
  122. * @lport: The local port to pass through a command
  123. * @rsp_code: The expected response code
  124. * @sg: job->reply_payload.sg_list
  125. * @nents: job->reply_payload.sg_cnt
  126. * @offset: The offset into the response data
  127. */
  128. struct fc_bsg_info {
  129. struct fc_bsg_job *job;
  130. struct fc_lport *lport;
  131. u16 rsp_code;
  132. struct scatterlist *sg;
  133. u32 nents;
  134. size_t offset;
  135. };
  136. static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp)
  137. {
  138. fc_frame_free(fp);
  139. return 0;
  140. }
  141. /**
  142. * fc_lport_rport_callback() - Event handler for rport events
  143. * @lport: The lport which is receiving the event
  144. * @rdata: private remote port data
  145. * @event: The event that occured
  146. *
  147. * Locking Note: The rport lock should not be held when calling
  148. * this function.
  149. */
  150. static void fc_lport_rport_callback(struct fc_lport *lport,
  151. struct fc_rport_priv *rdata,
  152. enum fc_rport_event event)
  153. {
  154. FC_LPORT_DBG(lport, "Received a %d event for port (%6x)\n", event,
  155. rdata->ids.port_id);
  156. mutex_lock(&lport->lp_mutex);
  157. switch (event) {
  158. case RPORT_EV_READY:
  159. if (lport->state == LPORT_ST_DNS) {
  160. lport->dns_rp = rdata;
  161. fc_lport_enter_ns(lport, LPORT_ST_RNN_ID);
  162. } else {
  163. FC_LPORT_DBG(lport, "Received an READY event "
  164. "on port (%6x) for the directory "
  165. "server, but the lport is not "
  166. "in the DNS state, it's in the "
  167. "%d state", rdata->ids.port_id,
  168. lport->state);
  169. lport->tt.rport_logoff(rdata);
  170. }
  171. break;
  172. case RPORT_EV_LOGO:
  173. case RPORT_EV_FAILED:
  174. case RPORT_EV_STOP:
  175. lport->dns_rp = NULL;
  176. break;
  177. case RPORT_EV_NONE:
  178. break;
  179. }
  180. mutex_unlock(&lport->lp_mutex);
  181. }
  182. /**
  183. * fc_lport_state() - Return a string which represents the lport's state
  184. * @lport: The lport whose state is to converted to a string
  185. */
  186. static const char *fc_lport_state(struct fc_lport *lport)
  187. {
  188. const char *cp;
  189. cp = fc_lport_state_names[lport->state];
  190. if (!cp)
  191. cp = "unknown";
  192. return cp;
  193. }
  194. /**
  195. * fc_lport_ptp_setup() - Create an rport for point-to-point mode
  196. * @lport: The lport to attach the ptp rport to
  197. * @fid: The FID of the ptp rport
  198. * @remote_wwpn: The WWPN of the ptp rport
  199. * @remote_wwnn: The WWNN of the ptp rport
  200. */
  201. static void fc_lport_ptp_setup(struct fc_lport *lport,
  202. u32 remote_fid, u64 remote_wwpn,
  203. u64 remote_wwnn)
  204. {
  205. mutex_lock(&lport->disc.disc_mutex);
  206. if (lport->ptp_rp)
  207. lport->tt.rport_logoff(lport->ptp_rp);
  208. lport->ptp_rp = lport->tt.rport_create(lport, remote_fid);
  209. lport->ptp_rp->ids.port_name = remote_wwpn;
  210. lport->ptp_rp->ids.node_name = remote_wwnn;
  211. mutex_unlock(&lport->disc.disc_mutex);
  212. lport->tt.rport_login(lport->ptp_rp);
  213. fc_lport_enter_ready(lport);
  214. }
  215. void fc_get_host_port_type(struct Scsi_Host *shost)
  216. {
  217. /* TODO - currently just NPORT */
  218. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  219. }
  220. EXPORT_SYMBOL(fc_get_host_port_type);
  221. void fc_get_host_port_state(struct Scsi_Host *shost)
  222. {
  223. struct fc_lport *lp = shost_priv(shost);
  224. mutex_lock(&lp->lp_mutex);
  225. if (!lp->link_up)
  226. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  227. else
  228. switch (lp->state) {
  229. case LPORT_ST_READY:
  230. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  231. break;
  232. default:
  233. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  234. }
  235. mutex_unlock(&lp->lp_mutex);
  236. }
  237. EXPORT_SYMBOL(fc_get_host_port_state);
  238. void fc_get_host_speed(struct Scsi_Host *shost)
  239. {
  240. struct fc_lport *lport = shost_priv(shost);
  241. fc_host_speed(shost) = lport->link_speed;
  242. }
  243. EXPORT_SYMBOL(fc_get_host_speed);
  244. struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost)
  245. {
  246. struct fc_host_statistics *fcoe_stats;
  247. struct fc_lport *lp = shost_priv(shost);
  248. struct timespec v0, v1;
  249. unsigned int cpu;
  250. fcoe_stats = &lp->host_stats;
  251. memset(fcoe_stats, 0, sizeof(struct fc_host_statistics));
  252. jiffies_to_timespec(jiffies, &v0);
  253. jiffies_to_timespec(lp->boot_time, &v1);
  254. fcoe_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec);
  255. for_each_possible_cpu(cpu) {
  256. struct fcoe_dev_stats *stats;
  257. stats = per_cpu_ptr(lp->dev_stats, cpu);
  258. fcoe_stats->tx_frames += stats->TxFrames;
  259. fcoe_stats->tx_words += stats->TxWords;
  260. fcoe_stats->rx_frames += stats->RxFrames;
  261. fcoe_stats->rx_words += stats->RxWords;
  262. fcoe_stats->error_frames += stats->ErrorFrames;
  263. fcoe_stats->invalid_crc_count += stats->InvalidCRCCount;
  264. fcoe_stats->fcp_input_requests += stats->InputRequests;
  265. fcoe_stats->fcp_output_requests += stats->OutputRequests;
  266. fcoe_stats->fcp_control_requests += stats->ControlRequests;
  267. fcoe_stats->fcp_input_megabytes += stats->InputMegabytes;
  268. fcoe_stats->fcp_output_megabytes += stats->OutputMegabytes;
  269. fcoe_stats->link_failure_count += stats->LinkFailureCount;
  270. }
  271. fcoe_stats->lip_count = -1;
  272. fcoe_stats->nos_count = -1;
  273. fcoe_stats->loss_of_sync_count = -1;
  274. fcoe_stats->loss_of_signal_count = -1;
  275. fcoe_stats->prim_seq_protocol_err_count = -1;
  276. fcoe_stats->dumped_frames = -1;
  277. return fcoe_stats;
  278. }
  279. EXPORT_SYMBOL(fc_get_host_stats);
  280. /*
  281. * Fill in FLOGI command for request.
  282. */
  283. static void
  284. fc_lport_flogi_fill(struct fc_lport *lport, struct fc_els_flogi *flogi,
  285. unsigned int op)
  286. {
  287. struct fc_els_csp *sp;
  288. struct fc_els_cssp *cp;
  289. memset(flogi, 0, sizeof(*flogi));
  290. flogi->fl_cmd = (u8) op;
  291. put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn);
  292. put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn);
  293. sp = &flogi->fl_csp;
  294. sp->sp_hi_ver = 0x20;
  295. sp->sp_lo_ver = 0x20;
  296. sp->sp_bb_cred = htons(10); /* this gets set by gateway */
  297. sp->sp_bb_data = htons((u16) lport->mfs);
  298. cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */
  299. cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
  300. if (op != ELS_FLOGI) {
  301. sp->sp_features = htons(FC_SP_FT_CIRO);
  302. sp->sp_tot_seq = htons(255); /* seq. we accept */
  303. sp->sp_rel_off = htons(0x1f);
  304. sp->sp_e_d_tov = htonl(lport->e_d_tov);
  305. cp->cp_rdfs = htons((u16) lport->mfs);
  306. cp->cp_con_seq = htons(255);
  307. cp->cp_open_seq = 1;
  308. }
  309. }
  310. /*
  311. * Add a supported FC-4 type.
  312. */
  313. static void fc_lport_add_fc4_type(struct fc_lport *lport, enum fc_fh_type type)
  314. {
  315. __be32 *mp;
  316. mp = &lport->fcts.ff_type_map[type / FC_NS_BPW];
  317. *mp = htonl(ntohl(*mp) | 1UL << (type % FC_NS_BPW));
  318. }
  319. /**
  320. * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report.
  321. * @lport: Fibre Channel local port recieving the RLIR
  322. * @sp: current sequence in the RLIR exchange
  323. * @fp: RLIR request frame
  324. *
  325. * Locking Note: The lport lock is expected to be held before calling
  326. * this function.
  327. */
  328. static void fc_lport_recv_rlir_req(struct fc_seq *sp, struct fc_frame *fp,
  329. struct fc_lport *lport)
  330. {
  331. FC_LPORT_DBG(lport, "Received RLIR request while in state %s\n",
  332. fc_lport_state(lport));
  333. lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
  334. fc_frame_free(fp);
  335. }
  336. /**
  337. * fc_lport_recv_echo_req() - Handle received ECHO request
  338. * @lport: Fibre Channel local port recieving the ECHO
  339. * @sp: current sequence in the ECHO exchange
  340. * @fp: ECHO request frame
  341. *
  342. * Locking Note: The lport lock is expected to be held before calling
  343. * this function.
  344. */
  345. static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp,
  346. struct fc_lport *lport)
  347. {
  348. struct fc_frame *fp;
  349. struct fc_exch *ep = fc_seq_exch(sp);
  350. unsigned int len;
  351. void *pp;
  352. void *dp;
  353. u32 f_ctl;
  354. FC_LPORT_DBG(lport, "Received ECHO request while in state %s\n",
  355. fc_lport_state(lport));
  356. len = fr_len(in_fp) - sizeof(struct fc_frame_header);
  357. pp = fc_frame_payload_get(in_fp, len);
  358. if (len < sizeof(__be32))
  359. len = sizeof(__be32);
  360. fp = fc_frame_alloc(lport, len);
  361. if (fp) {
  362. dp = fc_frame_payload_get(fp, len);
  363. memcpy(dp, pp, len);
  364. *((__be32 *)dp) = htonl(ELS_LS_ACC << 24);
  365. sp = lport->tt.seq_start_next(sp);
  366. f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ;
  367. fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
  368. FC_TYPE_ELS, f_ctl, 0);
  369. lport->tt.seq_send(lport, sp, fp);
  370. }
  371. fc_frame_free(in_fp);
  372. }
  373. /**
  374. * fc_lport_recv_rnid_req() - Handle received Request Node ID data request
  375. * @sp: The sequence in the RNID exchange
  376. * @fp: The RNID request frame
  377. * @lport: The local port recieving the RNID
  378. *
  379. * Locking Note: The lport lock is expected to be held before calling
  380. * this function.
  381. */
  382. static void fc_lport_recv_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp,
  383. struct fc_lport *lport)
  384. {
  385. struct fc_frame *fp;
  386. struct fc_exch *ep = fc_seq_exch(sp);
  387. struct fc_els_rnid *req;
  388. struct {
  389. struct fc_els_rnid_resp rnid;
  390. struct fc_els_rnid_cid cid;
  391. struct fc_els_rnid_gen gen;
  392. } *rp;
  393. struct fc_seq_els_data rjt_data;
  394. u8 fmt;
  395. size_t len;
  396. u32 f_ctl;
  397. FC_LPORT_DBG(lport, "Received RNID request while in state %s\n",
  398. fc_lport_state(lport));
  399. req = fc_frame_payload_get(in_fp, sizeof(*req));
  400. if (!req) {
  401. rjt_data.fp = NULL;
  402. rjt_data.reason = ELS_RJT_LOGIC;
  403. rjt_data.explan = ELS_EXPL_NONE;
  404. lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
  405. } else {
  406. fmt = req->rnid_fmt;
  407. len = sizeof(*rp);
  408. if (fmt != ELS_RNIDF_GEN ||
  409. ntohl(lport->rnid_gen.rnid_atype) == 0) {
  410. fmt = ELS_RNIDF_NONE; /* nothing to provide */
  411. len -= sizeof(rp->gen);
  412. }
  413. fp = fc_frame_alloc(lport, len);
  414. if (fp) {
  415. rp = fc_frame_payload_get(fp, len);
  416. memset(rp, 0, len);
  417. rp->rnid.rnid_cmd = ELS_LS_ACC;
  418. rp->rnid.rnid_fmt = fmt;
  419. rp->rnid.rnid_cid_len = sizeof(rp->cid);
  420. rp->cid.rnid_wwpn = htonll(lport->wwpn);
  421. rp->cid.rnid_wwnn = htonll(lport->wwnn);
  422. if (fmt == ELS_RNIDF_GEN) {
  423. rp->rnid.rnid_sid_len = sizeof(rp->gen);
  424. memcpy(&rp->gen, &lport->rnid_gen,
  425. sizeof(rp->gen));
  426. }
  427. sp = lport->tt.seq_start_next(sp);
  428. f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ;
  429. f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT;
  430. fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
  431. FC_TYPE_ELS, f_ctl, 0);
  432. lport->tt.seq_send(lport, sp, fp);
  433. }
  434. }
  435. fc_frame_free(in_fp);
  436. }
  437. /**
  438. * fc_lport_recv_logo_req() - Handle received fabric LOGO request
  439. * @lport: Fibre Channel local port recieving the LOGO
  440. * @sp: current sequence in the LOGO exchange
  441. * @fp: LOGO request frame
  442. *
  443. * Locking Note: The lport lock is exected to be held before calling
  444. * this function.
  445. */
  446. static void fc_lport_recv_logo_req(struct fc_seq *sp, struct fc_frame *fp,
  447. struct fc_lport *lport)
  448. {
  449. lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
  450. fc_lport_enter_reset(lport);
  451. fc_frame_free(fp);
  452. }
  453. /**
  454. * fc_fabric_login() - Start the lport state machine
  455. * @lport: The lport that should log into the fabric
  456. *
  457. * Locking Note: This function should not be called
  458. * with the lport lock held.
  459. */
  460. int fc_fabric_login(struct fc_lport *lport)
  461. {
  462. int rc = -1;
  463. mutex_lock(&lport->lp_mutex);
  464. if (lport->state == LPORT_ST_DISABLED) {
  465. fc_lport_enter_reset(lport);
  466. rc = 0;
  467. }
  468. mutex_unlock(&lport->lp_mutex);
  469. return rc;
  470. }
  471. EXPORT_SYMBOL(fc_fabric_login);
  472. /**
  473. * __fc_linkup() - Handler for transport linkup events
  474. * @lport: The lport whose link is up
  475. *
  476. * Locking: must be called with the lp_mutex held
  477. */
  478. void __fc_linkup(struct fc_lport *lport)
  479. {
  480. if (!lport->link_up) {
  481. lport->link_up = 1;
  482. if (lport->state == LPORT_ST_RESET)
  483. fc_lport_enter_flogi(lport);
  484. }
  485. }
  486. /**
  487. * fc_linkup() - Handler for transport linkup events
  488. * @lport: The lport whose link is up
  489. */
  490. void fc_linkup(struct fc_lport *lport)
  491. {
  492. printk(KERN_INFO "libfc: Link up on port (%6x)\n",
  493. fc_host_port_id(lport->host));
  494. mutex_lock(&lport->lp_mutex);
  495. __fc_linkup(lport);
  496. mutex_unlock(&lport->lp_mutex);
  497. }
  498. EXPORT_SYMBOL(fc_linkup);
  499. /**
  500. * __fc_linkdown() - Handler for transport linkdown events
  501. * @lport: The lport whose link is down
  502. *
  503. * Locking: must be called with the lp_mutex held
  504. */
  505. void __fc_linkdown(struct fc_lport *lport)
  506. {
  507. if (lport->link_up) {
  508. lport->link_up = 0;
  509. fc_lport_enter_reset(lport);
  510. lport->tt.fcp_cleanup(lport);
  511. }
  512. }
  513. /**
  514. * fc_linkdown() - Handler for transport linkdown events
  515. * @lport: The lport whose link is down
  516. */
  517. void fc_linkdown(struct fc_lport *lport)
  518. {
  519. printk(KERN_INFO "libfc: Link down on port (%6x)\n",
  520. fc_host_port_id(lport->host));
  521. mutex_lock(&lport->lp_mutex);
  522. __fc_linkdown(lport);
  523. mutex_unlock(&lport->lp_mutex);
  524. }
  525. EXPORT_SYMBOL(fc_linkdown);
  526. /**
  527. * fc_fabric_logoff() - Logout of the fabric
  528. * @lport: fc_lport pointer to logoff the fabric
  529. *
  530. * Return value:
  531. * 0 for success, -1 for failure
  532. */
  533. int fc_fabric_logoff(struct fc_lport *lport)
  534. {
  535. lport->tt.disc_stop_final(lport);
  536. mutex_lock(&lport->lp_mutex);
  537. if (lport->dns_rp)
  538. lport->tt.rport_logoff(lport->dns_rp);
  539. mutex_unlock(&lport->lp_mutex);
  540. lport->tt.rport_flush_queue();
  541. mutex_lock(&lport->lp_mutex);
  542. fc_lport_enter_logo(lport);
  543. mutex_unlock(&lport->lp_mutex);
  544. cancel_delayed_work_sync(&lport->retry_work);
  545. return 0;
  546. }
  547. EXPORT_SYMBOL(fc_fabric_logoff);
  548. /**
  549. * fc_lport_destroy() - unregister a fc_lport
  550. * @lport: fc_lport pointer to unregister
  551. *
  552. * Return value:
  553. * None
  554. * Note:
  555. * exit routine for fc_lport instance
  556. * clean-up all the allocated memory
  557. * and free up other system resources.
  558. *
  559. */
  560. int fc_lport_destroy(struct fc_lport *lport)
  561. {
  562. mutex_lock(&lport->lp_mutex);
  563. lport->state = LPORT_ST_DISABLED;
  564. lport->link_up = 0;
  565. lport->tt.frame_send = fc_frame_drop;
  566. mutex_unlock(&lport->lp_mutex);
  567. lport->tt.fcp_abort_io(lport);
  568. lport->tt.disc_stop_final(lport);
  569. lport->tt.exch_mgr_reset(lport, 0, 0);
  570. return 0;
  571. }
  572. EXPORT_SYMBOL(fc_lport_destroy);
  573. /**
  574. * fc_set_mfs() - sets up the mfs for the corresponding fc_lport
  575. * @lport: fc_lport pointer to unregister
  576. * @mfs: the new mfs for fc_lport
  577. *
  578. * Set mfs for the given fc_lport to the new mfs.
  579. *
  580. * Return: 0 for success
  581. */
  582. int fc_set_mfs(struct fc_lport *lport, u32 mfs)
  583. {
  584. unsigned int old_mfs;
  585. int rc = -EINVAL;
  586. mutex_lock(&lport->lp_mutex);
  587. old_mfs = lport->mfs;
  588. if (mfs >= FC_MIN_MAX_FRAME) {
  589. mfs &= ~3;
  590. if (mfs > FC_MAX_FRAME)
  591. mfs = FC_MAX_FRAME;
  592. mfs -= sizeof(struct fc_frame_header);
  593. lport->mfs = mfs;
  594. rc = 0;
  595. }
  596. if (!rc && mfs < old_mfs)
  597. fc_lport_enter_reset(lport);
  598. mutex_unlock(&lport->lp_mutex);
  599. return rc;
  600. }
  601. EXPORT_SYMBOL(fc_set_mfs);
  602. /**
  603. * fc_lport_disc_callback() - Callback for discovery events
  604. * @lport: FC local port
  605. * @event: The discovery event
  606. */
  607. void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event)
  608. {
  609. switch (event) {
  610. case DISC_EV_SUCCESS:
  611. FC_LPORT_DBG(lport, "Discovery succeeded\n");
  612. break;
  613. case DISC_EV_FAILED:
  614. printk(KERN_ERR "libfc: Discovery failed for port (%6x)\n",
  615. fc_host_port_id(lport->host));
  616. mutex_lock(&lport->lp_mutex);
  617. fc_lport_enter_reset(lport);
  618. mutex_unlock(&lport->lp_mutex);
  619. break;
  620. case DISC_EV_NONE:
  621. WARN_ON(1);
  622. break;
  623. }
  624. }
  625. /**
  626. * fc_rport_enter_ready() - Enter the ready state and start discovery
  627. * @lport: Fibre Channel local port that is ready
  628. *
  629. * Locking Note: The lport lock is expected to be held before calling
  630. * this routine.
  631. */
  632. static void fc_lport_enter_ready(struct fc_lport *lport)
  633. {
  634. FC_LPORT_DBG(lport, "Entered READY from state %s\n",
  635. fc_lport_state(lport));
  636. fc_lport_state_enter(lport, LPORT_ST_READY);
  637. if (lport->vport)
  638. fc_vport_set_state(lport->vport, FC_VPORT_ACTIVE);
  639. fc_vports_linkchange(lport);
  640. if (!lport->ptp_rp)
  641. lport->tt.disc_start(fc_lport_disc_callback, lport);
  642. }
  643. /**
  644. * fc_lport_recv_flogi_req() - Receive a FLOGI request
  645. * @sp_in: The sequence the FLOGI is on
  646. * @rx_fp: The frame the FLOGI is in
  647. * @lport: The lport that recieved the request
  648. *
  649. * A received FLOGI request indicates a point-to-point connection.
  650. * Accept it with the common service parameters indicating our N port.
  651. * Set up to do a PLOGI if we have the higher-number WWPN.
  652. *
  653. * Locking Note: The lport lock is expected to be held before calling
  654. * this function.
  655. */
  656. static void fc_lport_recv_flogi_req(struct fc_seq *sp_in,
  657. struct fc_frame *rx_fp,
  658. struct fc_lport *lport)
  659. {
  660. struct fc_frame *fp;
  661. struct fc_frame_header *fh;
  662. struct fc_seq *sp;
  663. struct fc_exch *ep;
  664. struct fc_els_flogi *flp;
  665. struct fc_els_flogi *new_flp;
  666. u64 remote_wwpn;
  667. u32 remote_fid;
  668. u32 local_fid;
  669. u32 f_ctl;
  670. FC_LPORT_DBG(lport, "Received FLOGI request while in state %s\n",
  671. fc_lport_state(lport));
  672. fh = fc_frame_header_get(rx_fp);
  673. remote_fid = ntoh24(fh->fh_s_id);
  674. flp = fc_frame_payload_get(rx_fp, sizeof(*flp));
  675. if (!flp)
  676. goto out;
  677. remote_wwpn = get_unaligned_be64(&flp->fl_wwpn);
  678. if (remote_wwpn == lport->wwpn) {
  679. printk(KERN_WARNING "libfc: Received FLOGI from port "
  680. "with same WWPN %llx\n", remote_wwpn);
  681. goto out;
  682. }
  683. FC_LPORT_DBG(lport, "FLOGI from port WWPN %llx\n", remote_wwpn);
  684. /*
  685. * XXX what is the right thing to do for FIDs?
  686. * The originator might expect our S_ID to be 0xfffffe.
  687. * But if so, both of us could end up with the same FID.
  688. */
  689. local_fid = FC_LOCAL_PTP_FID_LO;
  690. if (remote_wwpn < lport->wwpn) {
  691. local_fid = FC_LOCAL_PTP_FID_HI;
  692. if (!remote_fid || remote_fid == local_fid)
  693. remote_fid = FC_LOCAL_PTP_FID_LO;
  694. } else if (!remote_fid) {
  695. remote_fid = FC_LOCAL_PTP_FID_HI;
  696. }
  697. fc_host_port_id(lport->host) = local_fid;
  698. fp = fc_frame_alloc(lport, sizeof(*flp));
  699. if (fp) {
  700. sp = lport->tt.seq_start_next(fr_seq(rx_fp));
  701. new_flp = fc_frame_payload_get(fp, sizeof(*flp));
  702. fc_lport_flogi_fill(lport, new_flp, ELS_FLOGI);
  703. new_flp->fl_cmd = (u8) ELS_LS_ACC;
  704. /*
  705. * Send the response. If this fails, the originator should
  706. * repeat the sequence.
  707. */
  708. f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ;
  709. ep = fc_seq_exch(sp);
  710. fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
  711. FC_TYPE_ELS, f_ctl, 0);
  712. lport->tt.seq_send(lport, sp, fp);
  713. } else {
  714. fc_lport_error(lport, fp);
  715. }
  716. fc_lport_ptp_setup(lport, remote_fid, remote_wwpn,
  717. get_unaligned_be64(&flp->fl_wwnn));
  718. out:
  719. sp = fr_seq(rx_fp);
  720. fc_frame_free(rx_fp);
  721. }
  722. /**
  723. * fc_lport_recv_req() - The generic lport request handler
  724. * @lport: The lport that received the request
  725. * @sp: The sequence the request is on
  726. * @fp: The frame the request is in
  727. *
  728. * This function will see if the lport handles the request or
  729. * if an rport should handle the request.
  730. *
  731. * Locking Note: This function should not be called with the lport
  732. * lock held becuase it will grab the lock.
  733. */
  734. static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp,
  735. struct fc_frame *fp)
  736. {
  737. struct fc_frame_header *fh = fc_frame_header_get(fp);
  738. void (*recv) (struct fc_seq *, struct fc_frame *, struct fc_lport *);
  739. mutex_lock(&lport->lp_mutex);
  740. /*
  741. * Handle special ELS cases like FLOGI, LOGO, and
  742. * RSCN here. These don't require a session.
  743. * Even if we had a session, it might not be ready.
  744. */
  745. if (!lport->link_up)
  746. fc_frame_free(fp);
  747. else if (fh->fh_type == FC_TYPE_ELS &&
  748. fh->fh_r_ctl == FC_RCTL_ELS_REQ) {
  749. /*
  750. * Check opcode.
  751. */
  752. recv = lport->tt.rport_recv_req;
  753. switch (fc_frame_payload_op(fp)) {
  754. case ELS_FLOGI:
  755. recv = fc_lport_recv_flogi_req;
  756. break;
  757. case ELS_LOGO:
  758. fh = fc_frame_header_get(fp);
  759. if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI)
  760. recv = fc_lport_recv_logo_req;
  761. break;
  762. case ELS_RSCN:
  763. recv = lport->tt.disc_recv_req;
  764. break;
  765. case ELS_ECHO:
  766. recv = fc_lport_recv_echo_req;
  767. break;
  768. case ELS_RLIR:
  769. recv = fc_lport_recv_rlir_req;
  770. break;
  771. case ELS_RNID:
  772. recv = fc_lport_recv_rnid_req;
  773. break;
  774. }
  775. recv(sp, fp, lport);
  776. } else {
  777. FC_LPORT_DBG(lport, "dropping invalid frame (eof %x)\n",
  778. fr_eof(fp));
  779. fc_frame_free(fp);
  780. }
  781. mutex_unlock(&lport->lp_mutex);
  782. /*
  783. * The common exch_done for all request may not be good
  784. * if any request requires longer hold on exhange. XXX
  785. */
  786. lport->tt.exch_done(sp);
  787. }
  788. /**
  789. * fc_lport_reset() - Reset an lport
  790. * @lport: The lport which should be reset
  791. *
  792. * Locking Note: This functions should not be called with the
  793. * lport lock held.
  794. */
  795. int fc_lport_reset(struct fc_lport *lport)
  796. {
  797. cancel_delayed_work_sync(&lport->retry_work);
  798. mutex_lock(&lport->lp_mutex);
  799. fc_lport_enter_reset(lport);
  800. mutex_unlock(&lport->lp_mutex);
  801. return 0;
  802. }
  803. EXPORT_SYMBOL(fc_lport_reset);
  804. /**
  805. * fc_lport_reset_locked() - Reset the local port
  806. * @lport: Fibre Channel local port to be reset
  807. *
  808. * Locking Note: The lport lock is expected to be held before calling
  809. * this routine.
  810. */
  811. static void fc_lport_reset_locked(struct fc_lport *lport)
  812. {
  813. if (lport->dns_rp)
  814. lport->tt.rport_logoff(lport->dns_rp);
  815. lport->ptp_rp = NULL;
  816. lport->tt.disc_stop(lport);
  817. lport->tt.exch_mgr_reset(lport, 0, 0);
  818. fc_host_fabric_name(lport->host) = 0;
  819. fc_host_port_id(lport->host) = 0;
  820. }
  821. /**
  822. * fc_lport_enter_reset() - Reset the local port
  823. * @lport: Fibre Channel local port to be reset
  824. *
  825. * Locking Note: The lport lock is expected to be held before calling
  826. * this routine.
  827. */
  828. static void fc_lport_enter_reset(struct fc_lport *lport)
  829. {
  830. FC_LPORT_DBG(lport, "Entered RESET state from %s state\n",
  831. fc_lport_state(lport));
  832. if (lport->vport) {
  833. if (lport->link_up)
  834. fc_vport_set_state(lport->vport, FC_VPORT_INITIALIZING);
  835. else
  836. fc_vport_set_state(lport->vport, FC_VPORT_LINKDOWN);
  837. }
  838. fc_lport_state_enter(lport, LPORT_ST_RESET);
  839. fc_vports_linkchange(lport);
  840. fc_lport_reset_locked(lport);
  841. if (lport->link_up)
  842. fc_lport_enter_flogi(lport);
  843. }
  844. /**
  845. * fc_lport_enter_disabled() - disable the local port
  846. * @lport: Fibre Channel local port to be reset
  847. *
  848. * Locking Note: The lport lock is expected to be held before calling
  849. * this routine.
  850. */
  851. static void fc_lport_enter_disabled(struct fc_lport *lport)
  852. {
  853. FC_LPORT_DBG(lport, "Entered disabled state from %s state\n",
  854. fc_lport_state(lport));
  855. fc_lport_state_enter(lport, LPORT_ST_DISABLED);
  856. fc_vports_linkchange(lport);
  857. fc_lport_reset_locked(lport);
  858. }
  859. /**
  860. * fc_lport_error() - Handler for any errors
  861. * @lport: The fc_lport object
  862. * @fp: The frame pointer
  863. *
  864. * If the error was caused by a resource allocation failure
  865. * then wait for half a second and retry, otherwise retry
  866. * after the e_d_tov time.
  867. */
  868. static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp)
  869. {
  870. unsigned long delay = 0;
  871. FC_LPORT_DBG(lport, "Error %ld in state %s, retries %d\n",
  872. PTR_ERR(fp), fc_lport_state(lport),
  873. lport->retry_count);
  874. if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) {
  875. /*
  876. * Memory allocation failure, or the exchange timed out.
  877. * Retry after delay
  878. */
  879. if (lport->retry_count < lport->max_retry_count) {
  880. lport->retry_count++;
  881. if (!fp)
  882. delay = msecs_to_jiffies(500);
  883. else
  884. delay = msecs_to_jiffies(lport->e_d_tov);
  885. schedule_delayed_work(&lport->retry_work, delay);
  886. } else {
  887. switch (lport->state) {
  888. case LPORT_ST_DISABLED:
  889. case LPORT_ST_READY:
  890. case LPORT_ST_RESET:
  891. case LPORT_ST_RNN_ID:
  892. case LPORT_ST_RSNN_NN:
  893. case LPORT_ST_RSPN_ID:
  894. case LPORT_ST_RFT_ID:
  895. case LPORT_ST_SCR:
  896. case LPORT_ST_DNS:
  897. case LPORT_ST_FLOGI:
  898. case LPORT_ST_LOGO:
  899. fc_lport_enter_reset(lport);
  900. break;
  901. }
  902. }
  903. }
  904. }
  905. /**
  906. * fc_lport_ns_resp() - Handle response to a name server
  907. * registration exchange
  908. * @sp: current sequence in exchange
  909. * @fp: response frame
  910. * @lp_arg: Fibre Channel host port instance
  911. *
  912. * Locking Note: This function will be called without the lport lock
  913. * held, but it will lock, call an _enter_* function or fc_lport_error
  914. * and then unlock the lport.
  915. */
  916. static void fc_lport_ns_resp(struct fc_seq *sp, struct fc_frame *fp,
  917. void *lp_arg)
  918. {
  919. struct fc_lport *lport = lp_arg;
  920. struct fc_frame_header *fh;
  921. struct fc_ct_hdr *ct;
  922. FC_LPORT_DBG(lport, "Received a ns %s\n", fc_els_resp_type(fp));
  923. if (fp == ERR_PTR(-FC_EX_CLOSED))
  924. return;
  925. mutex_lock(&lport->lp_mutex);
  926. if (lport->state < LPORT_ST_RNN_ID || lport->state > LPORT_ST_RFT_ID) {
  927. FC_LPORT_DBG(lport, "Received a name server response, "
  928. "but in state %s\n", fc_lport_state(lport));
  929. if (IS_ERR(fp))
  930. goto err;
  931. goto out;
  932. }
  933. if (IS_ERR(fp)) {
  934. fc_lport_error(lport, fp);
  935. goto err;
  936. }
  937. fh = fc_frame_header_get(fp);
  938. ct = fc_frame_payload_get(fp, sizeof(*ct));
  939. if (fh && ct && fh->fh_type == FC_TYPE_CT &&
  940. ct->ct_fs_type == FC_FST_DIR &&
  941. ct->ct_fs_subtype == FC_NS_SUBTYPE &&
  942. ntohs(ct->ct_cmd) == FC_FS_ACC)
  943. switch (lport->state) {
  944. case LPORT_ST_RNN_ID:
  945. fc_lport_enter_ns(lport, LPORT_ST_RSNN_NN);
  946. break;
  947. case LPORT_ST_RSNN_NN:
  948. fc_lport_enter_ns(lport, LPORT_ST_RSPN_ID);
  949. break;
  950. case LPORT_ST_RSPN_ID:
  951. fc_lport_enter_ns(lport, LPORT_ST_RFT_ID);
  952. break;
  953. case LPORT_ST_RFT_ID:
  954. fc_lport_enter_scr(lport);
  955. break;
  956. default:
  957. /* should have already been caught by state checks */
  958. break;
  959. }
  960. else
  961. fc_lport_error(lport, fp);
  962. out:
  963. fc_frame_free(fp);
  964. err:
  965. mutex_unlock(&lport->lp_mutex);
  966. }
  967. /**
  968. * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request
  969. * @sp: current sequence in SCR exchange
  970. * @fp: response frame
  971. * @lp_arg: Fibre Channel lport port instance that sent the registration request
  972. *
  973. * Locking Note: This function will be called without the lport lock
  974. * held, but it will lock, call an _enter_* function or fc_lport_error
  975. * and then unlock the lport.
  976. */
  977. static void fc_lport_scr_resp(struct fc_seq *sp, struct fc_frame *fp,
  978. void *lp_arg)
  979. {
  980. struct fc_lport *lport = lp_arg;
  981. u8 op;
  982. FC_LPORT_DBG(lport, "Received a SCR %s\n", fc_els_resp_type(fp));
  983. if (fp == ERR_PTR(-FC_EX_CLOSED))
  984. return;
  985. mutex_lock(&lport->lp_mutex);
  986. if (lport->state != LPORT_ST_SCR) {
  987. FC_LPORT_DBG(lport, "Received a SCR response, but in state "
  988. "%s\n", fc_lport_state(lport));
  989. if (IS_ERR(fp))
  990. goto err;
  991. goto out;
  992. }
  993. if (IS_ERR(fp)) {
  994. fc_lport_error(lport, fp);
  995. goto err;
  996. }
  997. op = fc_frame_payload_op(fp);
  998. if (op == ELS_LS_ACC)
  999. fc_lport_enter_ready(lport);
  1000. else
  1001. fc_lport_error(lport, fp);
  1002. out:
  1003. fc_frame_free(fp);
  1004. err:
  1005. mutex_unlock(&lport->lp_mutex);
  1006. }
  1007. /**
  1008. * fc_lport_enter_scr() - Send a State Change Register (SCR) request
  1009. * @lport: Fibre Channel local port to register for state changes
  1010. *
  1011. * Locking Note: The lport lock is expected to be held before calling
  1012. * this routine.
  1013. */
  1014. static void fc_lport_enter_scr(struct fc_lport *lport)
  1015. {
  1016. struct fc_frame *fp;
  1017. FC_LPORT_DBG(lport, "Entered SCR state from %s state\n",
  1018. fc_lport_state(lport));
  1019. fc_lport_state_enter(lport, LPORT_ST_SCR);
  1020. fp = fc_frame_alloc(lport, sizeof(struct fc_els_scr));
  1021. if (!fp) {
  1022. fc_lport_error(lport, fp);
  1023. return;
  1024. }
  1025. if (!lport->tt.elsct_send(lport, FC_FID_FCTRL, fp, ELS_SCR,
  1026. fc_lport_scr_resp, lport, lport->e_d_tov))
  1027. fc_lport_error(lport, NULL);
  1028. }
  1029. /**
  1030. * fc_lport_enter_ns() - register some object with the name server
  1031. * @lport: Fibre Channel local port to register
  1032. *
  1033. * Locking Note: The lport lock is expected to be held before calling
  1034. * this routine.
  1035. */
  1036. static void fc_lport_enter_ns(struct fc_lport *lport, enum fc_lport_state state)
  1037. {
  1038. struct fc_frame *fp;
  1039. enum fc_ns_req cmd;
  1040. int size = sizeof(struct fc_ct_hdr);
  1041. size_t len;
  1042. FC_LPORT_DBG(lport, "Entered %s state from %s state\n",
  1043. fc_lport_state_names[state],
  1044. fc_lport_state(lport));
  1045. fc_lport_state_enter(lport, state);
  1046. switch (state) {
  1047. case LPORT_ST_RNN_ID:
  1048. cmd = FC_NS_RNN_ID;
  1049. size += sizeof(struct fc_ns_rn_id);
  1050. break;
  1051. case LPORT_ST_RSNN_NN:
  1052. len = strnlen(fc_host_symbolic_name(lport->host), 255);
  1053. /* if there is no symbolic name, skip to RFT_ID */
  1054. if (!len)
  1055. return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID);
  1056. cmd = FC_NS_RSNN_NN;
  1057. size += sizeof(struct fc_ns_rsnn) + len;
  1058. break;
  1059. case LPORT_ST_RSPN_ID:
  1060. len = strnlen(fc_host_symbolic_name(lport->host), 255);
  1061. /* if there is no symbolic name, skip to RFT_ID */
  1062. if (!len)
  1063. return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID);
  1064. cmd = FC_NS_RSPN_ID;
  1065. size += sizeof(struct fc_ns_rspn) + len;
  1066. break;
  1067. case LPORT_ST_RFT_ID:
  1068. cmd = FC_NS_RFT_ID;
  1069. size += sizeof(struct fc_ns_rft);
  1070. break;
  1071. default:
  1072. fc_lport_error(lport, NULL);
  1073. return;
  1074. }
  1075. fp = fc_frame_alloc(lport, size);
  1076. if (!fp) {
  1077. fc_lport_error(lport, fp);
  1078. return;
  1079. }
  1080. if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, cmd,
  1081. fc_lport_ns_resp,
  1082. lport, lport->e_d_tov))
  1083. fc_lport_error(lport, fp);
  1084. }
  1085. static struct fc_rport_operations fc_lport_rport_ops = {
  1086. .event_callback = fc_lport_rport_callback,
  1087. };
  1088. /**
  1089. * fc_rport_enter_dns() - Create a rport to the name server
  1090. * @lport: Fibre Channel local port requesting a rport for the name server
  1091. *
  1092. * Locking Note: The lport lock is expected to be held before calling
  1093. * this routine.
  1094. */
  1095. static void fc_lport_enter_dns(struct fc_lport *lport)
  1096. {
  1097. struct fc_rport_priv *rdata;
  1098. FC_LPORT_DBG(lport, "Entered DNS state from %s state\n",
  1099. fc_lport_state(lport));
  1100. fc_lport_state_enter(lport, LPORT_ST_DNS);
  1101. mutex_lock(&lport->disc.disc_mutex);
  1102. rdata = lport->tt.rport_create(lport, FC_FID_DIR_SERV);
  1103. mutex_unlock(&lport->disc.disc_mutex);
  1104. if (!rdata)
  1105. goto err;
  1106. rdata->ops = &fc_lport_rport_ops;
  1107. lport->tt.rport_login(rdata);
  1108. return;
  1109. err:
  1110. fc_lport_error(lport, NULL);
  1111. }
  1112. /**
  1113. * fc_lport_timeout() - Handler for the retry_work timer.
  1114. * @work: The work struct of the fc_lport
  1115. */
  1116. static void fc_lport_timeout(struct work_struct *work)
  1117. {
  1118. struct fc_lport *lport =
  1119. container_of(work, struct fc_lport,
  1120. retry_work.work);
  1121. mutex_lock(&lport->lp_mutex);
  1122. switch (lport->state) {
  1123. case LPORT_ST_DISABLED:
  1124. WARN_ON(1);
  1125. break;
  1126. case LPORT_ST_READY:
  1127. WARN_ON(1);
  1128. break;
  1129. case LPORT_ST_RESET:
  1130. break;
  1131. case LPORT_ST_FLOGI:
  1132. fc_lport_enter_flogi(lport);
  1133. break;
  1134. case LPORT_ST_DNS:
  1135. fc_lport_enter_dns(lport);
  1136. break;
  1137. case LPORT_ST_RNN_ID:
  1138. case LPORT_ST_RSNN_NN:
  1139. case LPORT_ST_RSPN_ID:
  1140. case LPORT_ST_RFT_ID:
  1141. fc_lport_enter_ns(lport, lport->state);
  1142. break;
  1143. case LPORT_ST_SCR:
  1144. fc_lport_enter_scr(lport);
  1145. break;
  1146. case LPORT_ST_LOGO:
  1147. fc_lport_enter_logo(lport);
  1148. break;
  1149. }
  1150. mutex_unlock(&lport->lp_mutex);
  1151. }
  1152. /**
  1153. * fc_lport_logo_resp() - Handle response to LOGO request
  1154. * @sp: current sequence in LOGO exchange
  1155. * @fp: response frame
  1156. * @lp_arg: Fibre Channel lport port instance that sent the LOGO request
  1157. *
  1158. * Locking Note: This function will be called without the lport lock
  1159. * held, but it will lock, call an _enter_* function or fc_lport_error
  1160. * and then unlock the lport.
  1161. */
  1162. void fc_lport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
  1163. void *lp_arg)
  1164. {
  1165. struct fc_lport *lport = lp_arg;
  1166. u8 op;
  1167. FC_LPORT_DBG(lport, "Received a LOGO %s\n", fc_els_resp_type(fp));
  1168. if (fp == ERR_PTR(-FC_EX_CLOSED))
  1169. return;
  1170. mutex_lock(&lport->lp_mutex);
  1171. if (lport->state != LPORT_ST_LOGO) {
  1172. FC_LPORT_DBG(lport, "Received a LOGO response, but in state "
  1173. "%s\n", fc_lport_state(lport));
  1174. if (IS_ERR(fp))
  1175. goto err;
  1176. goto out;
  1177. }
  1178. if (IS_ERR(fp)) {
  1179. fc_lport_error(lport, fp);
  1180. goto err;
  1181. }
  1182. op = fc_frame_payload_op(fp);
  1183. if (op == ELS_LS_ACC)
  1184. fc_lport_enter_disabled(lport);
  1185. else
  1186. fc_lport_error(lport, fp);
  1187. out:
  1188. fc_frame_free(fp);
  1189. err:
  1190. mutex_unlock(&lport->lp_mutex);
  1191. }
  1192. EXPORT_SYMBOL(fc_lport_logo_resp);
  1193. /**
  1194. * fc_rport_enter_logo() - Logout of the fabric
  1195. * @lport: Fibre Channel local port to be logged out
  1196. *
  1197. * Locking Note: The lport lock is expected to be held before calling
  1198. * this routine.
  1199. */
  1200. static void fc_lport_enter_logo(struct fc_lport *lport)
  1201. {
  1202. struct fc_frame *fp;
  1203. struct fc_els_logo *logo;
  1204. FC_LPORT_DBG(lport, "Entered LOGO state from %s state\n",
  1205. fc_lport_state(lport));
  1206. fc_lport_state_enter(lport, LPORT_ST_LOGO);
  1207. fc_vports_linkchange(lport);
  1208. fp = fc_frame_alloc(lport, sizeof(*logo));
  1209. if (!fp) {
  1210. fc_lport_error(lport, fp);
  1211. return;
  1212. }
  1213. if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, ELS_LOGO,
  1214. fc_lport_logo_resp, lport, lport->e_d_tov))
  1215. fc_lport_error(lport, NULL);
  1216. }
  1217. /**
  1218. * fc_lport_flogi_resp() - Handle response to FLOGI request
  1219. * @sp: current sequence in FLOGI exchange
  1220. * @fp: response frame
  1221. * @lp_arg: Fibre Channel lport port instance that sent the FLOGI request
  1222. *
  1223. * Locking Note: This function will be called without the lport lock
  1224. * held, but it will lock, call an _enter_* function or fc_lport_error
  1225. * and then unlock the lport.
  1226. */
  1227. void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
  1228. void *lp_arg)
  1229. {
  1230. struct fc_lport *lport = lp_arg;
  1231. struct fc_frame_header *fh;
  1232. struct fc_els_flogi *flp;
  1233. u32 did;
  1234. u16 csp_flags;
  1235. unsigned int r_a_tov;
  1236. unsigned int e_d_tov;
  1237. u16 mfs;
  1238. FC_LPORT_DBG(lport, "Received a FLOGI %s\n", fc_els_resp_type(fp));
  1239. if (fp == ERR_PTR(-FC_EX_CLOSED))
  1240. return;
  1241. mutex_lock(&lport->lp_mutex);
  1242. if (lport->state != LPORT_ST_FLOGI) {
  1243. FC_LPORT_DBG(lport, "Received a FLOGI response, but in state "
  1244. "%s\n", fc_lport_state(lport));
  1245. if (IS_ERR(fp))
  1246. goto err;
  1247. goto out;
  1248. }
  1249. if (IS_ERR(fp)) {
  1250. fc_lport_error(lport, fp);
  1251. goto err;
  1252. }
  1253. fh = fc_frame_header_get(fp);
  1254. did = ntoh24(fh->fh_d_id);
  1255. if (fc_frame_payload_op(fp) == ELS_LS_ACC && did != 0) {
  1256. printk(KERN_INFO "libfc: Assigned FID (%6x) in FLOGI response\n",
  1257. did);
  1258. fc_host_port_id(lport->host) = did;
  1259. flp = fc_frame_payload_get(fp, sizeof(*flp));
  1260. if (flp) {
  1261. mfs = ntohs(flp->fl_csp.sp_bb_data) &
  1262. FC_SP_BB_DATA_MASK;
  1263. if (mfs >= FC_SP_MIN_MAX_PAYLOAD &&
  1264. mfs < lport->mfs)
  1265. lport->mfs = mfs;
  1266. csp_flags = ntohs(flp->fl_csp.sp_features);
  1267. r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov);
  1268. e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov);
  1269. if (csp_flags & FC_SP_FT_EDTR)
  1270. e_d_tov /= 1000000;
  1271. lport->npiv_enabled = !!(csp_flags & FC_SP_FT_NPIV_ACC);
  1272. if ((csp_flags & FC_SP_FT_FPORT) == 0) {
  1273. if (e_d_tov > lport->e_d_tov)
  1274. lport->e_d_tov = e_d_tov;
  1275. lport->r_a_tov = 2 * e_d_tov;
  1276. printk(KERN_INFO "libfc: Port (%6x) entered "
  1277. "point to point mode\n", did);
  1278. fc_lport_ptp_setup(lport, ntoh24(fh->fh_s_id),
  1279. get_unaligned_be64(
  1280. &flp->fl_wwpn),
  1281. get_unaligned_be64(
  1282. &flp->fl_wwnn));
  1283. } else {
  1284. lport->e_d_tov = e_d_tov;
  1285. lport->r_a_tov = r_a_tov;
  1286. fc_host_fabric_name(lport->host) =
  1287. get_unaligned_be64(&flp->fl_wwnn);
  1288. fc_lport_enter_dns(lport);
  1289. }
  1290. }
  1291. } else {
  1292. FC_LPORT_DBG(lport, "Bad FLOGI response\n");
  1293. }
  1294. out:
  1295. fc_frame_free(fp);
  1296. err:
  1297. mutex_unlock(&lport->lp_mutex);
  1298. }
  1299. EXPORT_SYMBOL(fc_lport_flogi_resp);
  1300. /**
  1301. * fc_rport_enter_flogi() - Send a FLOGI request to the fabric manager
  1302. * @lport: Fibre Channel local port to be logged in to the fabric
  1303. *
  1304. * Locking Note: The lport lock is expected to be held before calling
  1305. * this routine.
  1306. */
  1307. void fc_lport_enter_flogi(struct fc_lport *lport)
  1308. {
  1309. struct fc_frame *fp;
  1310. FC_LPORT_DBG(lport, "Entered FLOGI state from %s state\n",
  1311. fc_lport_state(lport));
  1312. fc_lport_state_enter(lport, LPORT_ST_FLOGI);
  1313. fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
  1314. if (!fp)
  1315. return fc_lport_error(lport, fp);
  1316. if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp,
  1317. lport->vport ? ELS_FDISC : ELS_FLOGI,
  1318. fc_lport_flogi_resp, lport, lport->e_d_tov))
  1319. fc_lport_error(lport, NULL);
  1320. }
  1321. /* Configure a fc_lport */
  1322. int fc_lport_config(struct fc_lport *lport)
  1323. {
  1324. INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout);
  1325. mutex_init(&lport->lp_mutex);
  1326. fc_lport_state_enter(lport, LPORT_ST_DISABLED);
  1327. fc_lport_add_fc4_type(lport, FC_TYPE_FCP);
  1328. fc_lport_add_fc4_type(lport, FC_TYPE_CT);
  1329. return 0;
  1330. }
  1331. EXPORT_SYMBOL(fc_lport_config);
  1332. int fc_lport_init(struct fc_lport *lport)
  1333. {
  1334. if (!lport->tt.lport_recv)
  1335. lport->tt.lport_recv = fc_lport_recv_req;
  1336. if (!lport->tt.lport_reset)
  1337. lport->tt.lport_reset = fc_lport_reset;
  1338. fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
  1339. fc_host_node_name(lport->host) = lport->wwnn;
  1340. fc_host_port_name(lport->host) = lport->wwpn;
  1341. fc_host_supported_classes(lport->host) = FC_COS_CLASS3;
  1342. memset(fc_host_supported_fc4s(lport->host), 0,
  1343. sizeof(fc_host_supported_fc4s(lport->host)));
  1344. fc_host_supported_fc4s(lport->host)[2] = 1;
  1345. fc_host_supported_fc4s(lport->host)[7] = 1;
  1346. /* This value is also unchanging */
  1347. memset(fc_host_active_fc4s(lport->host), 0,
  1348. sizeof(fc_host_active_fc4s(lport->host)));
  1349. fc_host_active_fc4s(lport->host)[2] = 1;
  1350. fc_host_active_fc4s(lport->host)[7] = 1;
  1351. fc_host_maxframe_size(lport->host) = lport->mfs;
  1352. fc_host_supported_speeds(lport->host) = 0;
  1353. if (lport->link_supported_speeds & FC_PORTSPEED_1GBIT)
  1354. fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT;
  1355. if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT)
  1356. fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT;
  1357. return 0;
  1358. }
  1359. EXPORT_SYMBOL(fc_lport_init);
  1360. /**
  1361. * fc_lport_bsg_resp() - The common response handler for fc pass-thru requests
  1362. * @sp: current sequence in the fc pass-thru request exchange
  1363. * @fp: received response frame
  1364. * @info_arg: pointer to struct fc_bsg_info
  1365. */
  1366. static void fc_lport_bsg_resp(struct fc_seq *sp, struct fc_frame *fp,
  1367. void *info_arg)
  1368. {
  1369. struct fc_bsg_info *info = info_arg;
  1370. struct fc_bsg_job *job = info->job;
  1371. struct fc_lport *lport = info->lport;
  1372. struct fc_frame_header *fh;
  1373. size_t len;
  1374. void *buf;
  1375. if (IS_ERR(fp)) {
  1376. job->reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
  1377. -ECONNABORTED : -ETIMEDOUT;
  1378. job->reply_len = sizeof(uint32_t);
  1379. job->state_flags |= FC_RQST_STATE_DONE;
  1380. job->job_done(job);
  1381. kfree(info);
  1382. return;
  1383. }
  1384. mutex_lock(&lport->lp_mutex);
  1385. fh = fc_frame_header_get(fp);
  1386. len = fr_len(fp) - sizeof(*fh);
  1387. buf = fc_frame_payload_get(fp, 0);
  1388. if (fr_sof(fp) == FC_SOF_I3 && !ntohs(fh->fh_seq_cnt)) {
  1389. /* Get the response code from the first frame payload */
  1390. unsigned short cmd = (info->rsp_code == FC_FS_ACC) ?
  1391. ntohs(((struct fc_ct_hdr *)buf)->ct_cmd) :
  1392. (unsigned short)fc_frame_payload_op(fp);
  1393. /* Save the reply status of the job */
  1394. job->reply->reply_data.ctels_reply.status =
  1395. (cmd == info->rsp_code) ?
  1396. FC_CTELS_STATUS_OK : FC_CTELS_STATUS_REJECT;
  1397. }
  1398. job->reply->reply_payload_rcv_len +=
  1399. fc_copy_buffer_to_sglist(buf, len, info->sg, &info->nents,
  1400. &info->offset, KM_BIO_SRC_IRQ, NULL);
  1401. if (fr_eof(fp) == FC_EOF_T &&
  1402. (ntoh24(fh->fh_f_ctl) & (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) ==
  1403. (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) {
  1404. if (job->reply->reply_payload_rcv_len >
  1405. job->reply_payload.payload_len)
  1406. job->reply->reply_payload_rcv_len =
  1407. job->reply_payload.payload_len;
  1408. job->reply->result = 0;
  1409. job->state_flags |= FC_RQST_STATE_DONE;
  1410. job->job_done(job);
  1411. kfree(info);
  1412. }
  1413. fc_frame_free(fp);
  1414. mutex_unlock(&lport->lp_mutex);
  1415. }
  1416. /**
  1417. * fc_lport_els_request() - Send ELS pass-thru request
  1418. * @job: The bsg fc pass-thru job structure
  1419. * @lport: The local port sending the request
  1420. * @did: The destination port id.
  1421. *
  1422. * Locking Note: The lport lock is expected to be held before calling
  1423. * this routine.
  1424. */
  1425. static int fc_lport_els_request(struct fc_bsg_job *job,
  1426. struct fc_lport *lport,
  1427. u32 did, u32 tov)
  1428. {
  1429. struct fc_bsg_info *info;
  1430. struct fc_frame *fp;
  1431. struct fc_frame_header *fh;
  1432. char *pp;
  1433. int len;
  1434. fp = fc_frame_alloc(lport, sizeof(struct fc_frame_header) +
  1435. job->request_payload.payload_len);
  1436. if (!fp)
  1437. return -ENOMEM;
  1438. len = job->request_payload.payload_len;
  1439. pp = fc_frame_payload_get(fp, len);
  1440. sg_copy_to_buffer(job->request_payload.sg_list,
  1441. job->request_payload.sg_cnt,
  1442. pp, len);
  1443. fh = fc_frame_header_get(fp);
  1444. fh->fh_r_ctl = FC_RCTL_ELS_REQ;
  1445. hton24(fh->fh_d_id, did);
  1446. hton24(fh->fh_s_id, fc_host_port_id(lport->host));
  1447. fh->fh_type = FC_TYPE_ELS;
  1448. hton24(fh->fh_f_ctl, FC_FC_FIRST_SEQ |
  1449. FC_FC_END_SEQ | FC_FC_SEQ_INIT);
  1450. fh->fh_cs_ctl = 0;
  1451. fh->fh_df_ctl = 0;
  1452. fh->fh_parm_offset = 0;
  1453. info = kzalloc(sizeof(struct fc_bsg_info), GFP_KERNEL);
  1454. if (!info) {
  1455. fc_frame_free(fp);
  1456. return -ENOMEM;
  1457. }
  1458. info->job = job;
  1459. info->lport = lport;
  1460. info->rsp_code = ELS_LS_ACC;
  1461. info->nents = job->reply_payload.sg_cnt;
  1462. info->sg = job->reply_payload.sg_list;
  1463. if (!lport->tt.exch_seq_send(lport, fp, fc_lport_bsg_resp,
  1464. NULL, info, tov))
  1465. return -ECOMM;
  1466. return 0;
  1467. }
  1468. /**
  1469. * fc_lport_ct_request() - Send CT pass-thru request
  1470. * @job: The bsg fc pass-thru job structure
  1471. * @lport: The local port sending the request
  1472. * @did: The destination FC-ID
  1473. * @tov: The time to wait for a response
  1474. *
  1475. * Locking Note: The lport lock is expected to be held before calling
  1476. * this routine.
  1477. */
  1478. static int fc_lport_ct_request(struct fc_bsg_job *job,
  1479. struct fc_lport *lport, u32 did, u32 tov)
  1480. {
  1481. struct fc_bsg_info *info;
  1482. struct fc_frame *fp;
  1483. struct fc_frame_header *fh;
  1484. struct fc_ct_req *ct;
  1485. size_t len;
  1486. fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) +
  1487. job->request_payload.payload_len);
  1488. if (!fp)
  1489. return -ENOMEM;
  1490. len = job->request_payload.payload_len;
  1491. ct = fc_frame_payload_get(fp, len);
  1492. sg_copy_to_buffer(job->request_payload.sg_list,
  1493. job->request_payload.sg_cnt,
  1494. ct, len);
  1495. fh = fc_frame_header_get(fp);
  1496. fh->fh_r_ctl = FC_RCTL_DD_UNSOL_CTL;
  1497. hton24(fh->fh_d_id, did);
  1498. hton24(fh->fh_s_id, fc_host_port_id(lport->host));
  1499. fh->fh_type = FC_TYPE_CT;
  1500. hton24(fh->fh_f_ctl, FC_FC_FIRST_SEQ |
  1501. FC_FC_END_SEQ | FC_FC_SEQ_INIT);
  1502. fh->fh_cs_ctl = 0;
  1503. fh->fh_df_ctl = 0;
  1504. fh->fh_parm_offset = 0;
  1505. info = kzalloc(sizeof(struct fc_bsg_info), GFP_KERNEL);
  1506. if (!info) {
  1507. fc_frame_free(fp);
  1508. return -ENOMEM;
  1509. }
  1510. info->job = job;
  1511. info->lport = lport;
  1512. info->rsp_code = FC_FS_ACC;
  1513. info->nents = job->reply_payload.sg_cnt;
  1514. info->sg = job->reply_payload.sg_list;
  1515. if (!lport->tt.exch_seq_send(lport, fp, fc_lport_bsg_resp,
  1516. NULL, info, tov))
  1517. return -ECOMM;
  1518. return 0;
  1519. }
  1520. /**
  1521. * fc_lport_bsg_request() - The common entry point for sending
  1522. * fc pass-thru requests
  1523. * @job: The fc pass-thru job structure
  1524. */
  1525. int fc_lport_bsg_request(struct fc_bsg_job *job)
  1526. {
  1527. struct request *rsp = job->req->next_rq;
  1528. struct Scsi_Host *shost = job->shost;
  1529. struct fc_lport *lport = shost_priv(shost);
  1530. struct fc_rport *rport;
  1531. struct fc_rport_priv *rdata;
  1532. int rc = -EINVAL;
  1533. u32 did;
  1534. job->reply->reply_payload_rcv_len = 0;
  1535. rsp->resid_len = job->reply_payload.payload_len;
  1536. mutex_lock(&lport->lp_mutex);
  1537. switch (job->request->msgcode) {
  1538. case FC_BSG_RPT_ELS:
  1539. rport = job->rport;
  1540. if (!rport)
  1541. break;
  1542. rdata = rport->dd_data;
  1543. rc = fc_lport_els_request(job, lport, rport->port_id,
  1544. rdata->e_d_tov);
  1545. break;
  1546. case FC_BSG_RPT_CT:
  1547. rport = job->rport;
  1548. if (!rport)
  1549. break;
  1550. rdata = rport->dd_data;
  1551. rc = fc_lport_ct_request(job, lport, rport->port_id,
  1552. rdata->e_d_tov);
  1553. break;
  1554. case FC_BSG_HST_CT:
  1555. did = ntoh24(job->request->rqst_data.h_ct.port_id);
  1556. if (did == FC_FID_DIR_SERV)
  1557. rdata = lport->dns_rp;
  1558. else
  1559. rdata = lport->tt.rport_lookup(lport, did);
  1560. if (!rdata)
  1561. break;
  1562. rc = fc_lport_ct_request(job, lport, did, rdata->e_d_tov);
  1563. break;
  1564. case FC_BSG_HST_ELS_NOLOGIN:
  1565. did = ntoh24(job->request->rqst_data.h_els.port_id);
  1566. rc = fc_lport_els_request(job, lport, did, lport->e_d_tov);
  1567. break;
  1568. }
  1569. mutex_unlock(&lport->lp_mutex);
  1570. return rc;
  1571. }
  1572. EXPORT_SYMBOL(fc_lport_bsg_request);