fc_rport.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Maintained at www.Open-FCoE.org
  6. */
  7. /*
  8. * RPORT GENERAL INFO
  9. *
  10. * This file contains all processing regarding fc_rports. It contains the
  11. * rport state machine and does all rport interaction with the transport class.
  12. * There should be no other places in libfc that interact directly with the
  13. * transport class in regards to adding and deleting rports.
  14. *
  15. * fc_rport's represent N_Port's within the fabric.
  16. */
  17. /*
  18. * RPORT LOCKING
  19. *
  20. * The rport should never hold the rport mutex and then attempt to acquire
  21. * either the lport or disc mutexes. The rport's mutex is considered lesser
  22. * than both the lport's mutex and the disc mutex. Refer to fc_lport.c for
  23. * more comments on the hierarchy.
  24. *
  25. * The locking strategy is similar to the lport's strategy. The lock protects
  26. * the rport's states and is held and released by the entry points to the rport
  27. * block. All _enter_* functions correspond to rport states and expect the rport
  28. * mutex to be locked before calling them. This means that rports only handle
  29. * one request or response at a time, since they're not critical for the I/O
  30. * path this potential over-use of the mutex is acceptable.
  31. */
  32. /*
  33. * RPORT REFERENCE COUNTING
  34. *
  35. * A rport reference should be taken when:
  36. * - an rport is allocated
  37. * - a workqueue item is scheduled
  38. * - an ELS request is send
  39. * The reference should be dropped when:
  40. * - the workqueue function has finished
  41. * - the ELS response is handled
  42. * - an rport is removed
  43. */
  44. #include <linux/kernel.h>
  45. #include <linux/spinlock.h>
  46. #include <linux/interrupt.h>
  47. #include <linux/slab.h>
  48. #include <linux/rcupdate.h>
  49. #include <linux/timer.h>
  50. #include <linux/workqueue.h>
  51. #include <linux/export.h>
  52. #include <linux/rculist.h>
  53. #include <asm/unaligned.h>
  54. #include <scsi/libfc.h>
  55. #include <scsi/fc_encode.h>
  56. #include "fc_libfc.h"
  57. static struct workqueue_struct *rport_event_queue;
  58. static void fc_rport_enter_flogi(struct fc_rport_priv *);
  59. static void fc_rport_enter_plogi(struct fc_rport_priv *);
  60. static void fc_rport_enter_prli(struct fc_rport_priv *);
  61. static void fc_rport_enter_rtv(struct fc_rport_priv *);
  62. static void fc_rport_enter_ready(struct fc_rport_priv *);
  63. static void fc_rport_enter_logo(struct fc_rport_priv *);
  64. static void fc_rport_enter_adisc(struct fc_rport_priv *);
  65. static void fc_rport_recv_plogi_req(struct fc_lport *, struct fc_frame *);
  66. static void fc_rport_recv_prli_req(struct fc_rport_priv *, struct fc_frame *);
  67. static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
  68. static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
  69. static void fc_rport_timeout(struct work_struct *);
  70. static void fc_rport_error(struct fc_rport_priv *, int);
  71. static void fc_rport_error_retry(struct fc_rport_priv *, int);
  72. static void fc_rport_work(struct work_struct *);
  73. static const char *fc_rport_state_names[] = {
  74. [RPORT_ST_INIT] = "Init",
  75. [RPORT_ST_FLOGI] = "FLOGI",
  76. [RPORT_ST_PLOGI_WAIT] = "PLOGI_WAIT",
  77. [RPORT_ST_PLOGI] = "PLOGI",
  78. [RPORT_ST_PRLI] = "PRLI",
  79. [RPORT_ST_RTV] = "RTV",
  80. [RPORT_ST_READY] = "Ready",
  81. [RPORT_ST_ADISC] = "ADISC",
  82. [RPORT_ST_DELETE] = "Delete",
  83. };
  84. /**
  85. * fc_rport_lookup() - Lookup a remote port by port_id
  86. * @lport: The local port to lookup the remote port on
  87. * @port_id: The remote port ID to look up
  88. *
  89. * The reference count of the fc_rport_priv structure is
  90. * increased by one.
  91. */
  92. struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
  93. u32 port_id)
  94. {
  95. struct fc_rport_priv *rdata = NULL, *tmp_rdata;
  96. rcu_read_lock();
  97. list_for_each_entry_rcu(tmp_rdata, &lport->disc.rports, peers)
  98. if (tmp_rdata->ids.port_id == port_id &&
  99. kref_get_unless_zero(&tmp_rdata->kref)) {
  100. rdata = tmp_rdata;
  101. break;
  102. }
  103. rcu_read_unlock();
  104. return rdata;
  105. }
  106. EXPORT_SYMBOL(fc_rport_lookup);
  107. /**
  108. * fc_rport_create() - Create a new remote port
  109. * @lport: The local port this remote port will be associated with
  110. * @port_id: The identifiers for the new remote port
  111. *
  112. * The remote port will start in the INIT state.
  113. */
  114. struct fc_rport_priv *fc_rport_create(struct fc_lport *lport, u32 port_id)
  115. {
  116. struct fc_rport_priv *rdata;
  117. size_t rport_priv_size = sizeof(*rdata);
  118. lockdep_assert_held(&lport->disc.disc_mutex);
  119. rdata = fc_rport_lookup(lport, port_id);
  120. if (rdata) {
  121. kref_put(&rdata->kref, fc_rport_destroy);
  122. return rdata;
  123. }
  124. if (lport->rport_priv_size > 0)
  125. rport_priv_size = lport->rport_priv_size;
  126. rdata = kzalloc(rport_priv_size, GFP_KERNEL);
  127. if (!rdata)
  128. return NULL;
  129. rdata->ids.node_name = -1;
  130. rdata->ids.port_name = -1;
  131. rdata->ids.port_id = port_id;
  132. rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
  133. kref_init(&rdata->kref);
  134. mutex_init(&rdata->rp_mutex);
  135. rdata->local_port = lport;
  136. rdata->rp_state = RPORT_ST_INIT;
  137. rdata->event = RPORT_EV_NONE;
  138. rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
  139. rdata->e_d_tov = lport->e_d_tov;
  140. rdata->r_a_tov = lport->r_a_tov;
  141. rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
  142. INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
  143. INIT_WORK(&rdata->event_work, fc_rport_work);
  144. if (port_id != FC_FID_DIR_SERV) {
  145. rdata->lld_event_callback = lport->tt.rport_event_callback;
  146. list_add_rcu(&rdata->peers, &lport->disc.rports);
  147. }
  148. return rdata;
  149. }
  150. EXPORT_SYMBOL(fc_rport_create);
  151. /**
  152. * fc_rport_destroy() - Free a remote port after last reference is released
  153. * @kref: The remote port's kref
  154. */
  155. void fc_rport_destroy(struct kref *kref)
  156. {
  157. struct fc_rport_priv *rdata;
  158. rdata = container_of(kref, struct fc_rport_priv, kref);
  159. kfree_rcu(rdata, rcu);
  160. }
  161. EXPORT_SYMBOL(fc_rport_destroy);
  162. /**
  163. * fc_rport_state() - Return a string identifying the remote port's state
  164. * @rdata: The remote port
  165. */
  166. static const char *fc_rport_state(struct fc_rport_priv *rdata)
  167. {
  168. const char *cp;
  169. cp = fc_rport_state_names[rdata->rp_state];
  170. if (!cp)
  171. cp = "Unknown";
  172. return cp;
  173. }
  174. /**
  175. * fc_set_rport_loss_tmo() - Set the remote port loss timeout
  176. * @rport: The remote port that gets a new timeout value
  177. * @timeout: The new timeout value (in seconds)
  178. */
  179. void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
  180. {
  181. if (timeout)
  182. rport->dev_loss_tmo = timeout;
  183. else
  184. rport->dev_loss_tmo = 1;
  185. }
  186. EXPORT_SYMBOL(fc_set_rport_loss_tmo);
  187. /**
  188. * fc_plogi_get_maxframe() - Get the maximum payload from the common service
  189. * parameters in a FLOGI frame
  190. * @flp: The FLOGI or PLOGI payload
  191. * @maxval: The maximum frame size upper limit; this may be less than what
  192. * is in the service parameters
  193. */
  194. static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
  195. unsigned int maxval)
  196. {
  197. unsigned int mfs;
  198. /*
  199. * Get max payload from the common service parameters and the
  200. * class 3 receive data field size.
  201. */
  202. mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
  203. if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
  204. maxval = mfs;
  205. mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
  206. if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
  207. maxval = mfs;
  208. return maxval;
  209. }
  210. /**
  211. * fc_rport_state_enter() - Change the state of a remote port
  212. * @rdata: The remote port whose state should change
  213. * @new: The new state
  214. */
  215. static void fc_rport_state_enter(struct fc_rport_priv *rdata,
  216. enum fc_rport_state new)
  217. {
  218. lockdep_assert_held(&rdata->rp_mutex);
  219. if (rdata->rp_state != new)
  220. rdata->retries = 0;
  221. rdata->rp_state = new;
  222. }
  223. /**
  224. * fc_rport_work() - Handler for remote port events in the rport_event_queue
  225. * @work: Handle to the remote port being dequeued
  226. *
  227. * Reference counting: drops kref on return
  228. */
  229. static void fc_rport_work(struct work_struct *work)
  230. {
  231. u32 port_id;
  232. struct fc_rport_priv *rdata =
  233. container_of(work, struct fc_rport_priv, event_work);
  234. struct fc_rport_libfc_priv *rpriv;
  235. enum fc_rport_event event;
  236. struct fc_lport *lport = rdata->local_port;
  237. struct fc_rport_operations *rport_ops;
  238. struct fc_rport_identifiers ids;
  239. struct fc_rport *rport;
  240. struct fc4_prov *prov;
  241. u8 type;
  242. mutex_lock(&rdata->rp_mutex);
  243. event = rdata->event;
  244. rport_ops = rdata->ops;
  245. rport = rdata->rport;
  246. FC_RPORT_DBG(rdata, "work event %u\n", event);
  247. switch (event) {
  248. case RPORT_EV_READY:
  249. ids = rdata->ids;
  250. rdata->event = RPORT_EV_NONE;
  251. rdata->major_retries = 0;
  252. kref_get(&rdata->kref);
  253. mutex_unlock(&rdata->rp_mutex);
  254. if (!rport) {
  255. FC_RPORT_DBG(rdata, "No rport!\n");
  256. rport = fc_remote_port_add(lport->host, 0, &ids);
  257. }
  258. if (!rport) {
  259. FC_RPORT_DBG(rdata, "Failed to add the rport\n");
  260. fc_rport_logoff(rdata);
  261. kref_put(&rdata->kref, fc_rport_destroy);
  262. return;
  263. }
  264. mutex_lock(&rdata->rp_mutex);
  265. if (rdata->rport)
  266. FC_RPORT_DBG(rdata, "rport already allocated\n");
  267. rdata->rport = rport;
  268. rport->maxframe_size = rdata->maxframe_size;
  269. rport->supported_classes = rdata->supported_classes;
  270. rpriv = rport->dd_data;
  271. rpriv->local_port = lport;
  272. rpriv->rp_state = rdata->rp_state;
  273. rpriv->flags = rdata->flags;
  274. rpriv->e_d_tov = rdata->e_d_tov;
  275. rpriv->r_a_tov = rdata->r_a_tov;
  276. mutex_unlock(&rdata->rp_mutex);
  277. if (rport_ops && rport_ops->event_callback) {
  278. FC_RPORT_DBG(rdata, "callback ev %d\n", event);
  279. rport_ops->event_callback(lport, rdata, event);
  280. }
  281. if (rdata->lld_event_callback) {
  282. FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
  283. rdata->lld_event_callback(lport, rdata, event);
  284. }
  285. kref_put(&rdata->kref, fc_rport_destroy);
  286. break;
  287. case RPORT_EV_FAILED:
  288. case RPORT_EV_LOGO:
  289. case RPORT_EV_STOP:
  290. if (rdata->prli_count) {
  291. mutex_lock(&fc_prov_mutex);
  292. for (type = 1; type < FC_FC4_PROV_SIZE; type++) {
  293. prov = fc_passive_prov[type];
  294. if (prov && prov->prlo)
  295. prov->prlo(rdata);
  296. }
  297. mutex_unlock(&fc_prov_mutex);
  298. }
  299. port_id = rdata->ids.port_id;
  300. mutex_unlock(&rdata->rp_mutex);
  301. if (rport_ops && rport_ops->event_callback) {
  302. FC_RPORT_DBG(rdata, "callback ev %d\n", event);
  303. rport_ops->event_callback(lport, rdata, event);
  304. }
  305. if (rdata->lld_event_callback) {
  306. FC_RPORT_DBG(rdata, "lld callback ev %d\n", event);
  307. rdata->lld_event_callback(lport, rdata, event);
  308. }
  309. if (cancel_delayed_work_sync(&rdata->retry_work))
  310. kref_put(&rdata->kref, fc_rport_destroy);
  311. /*
  312. * Reset any outstanding exchanges before freeing rport.
  313. */
  314. lport->tt.exch_mgr_reset(lport, 0, port_id);
  315. lport->tt.exch_mgr_reset(lport, port_id, 0);
  316. if (rport) {
  317. rpriv = rport->dd_data;
  318. rpriv->rp_state = RPORT_ST_DELETE;
  319. mutex_lock(&rdata->rp_mutex);
  320. rdata->rport = NULL;
  321. mutex_unlock(&rdata->rp_mutex);
  322. fc_remote_port_delete(rport);
  323. }
  324. mutex_lock(&rdata->rp_mutex);
  325. if (rdata->rp_state == RPORT_ST_DELETE) {
  326. if (port_id == FC_FID_DIR_SERV) {
  327. rdata->event = RPORT_EV_NONE;
  328. mutex_unlock(&rdata->rp_mutex);
  329. kref_put(&rdata->kref, fc_rport_destroy);
  330. } else if ((rdata->flags & FC_RP_STARTED) &&
  331. rdata->major_retries <
  332. lport->max_rport_retry_count) {
  333. rdata->major_retries++;
  334. rdata->event = RPORT_EV_NONE;
  335. FC_RPORT_DBG(rdata, "work restart\n");
  336. fc_rport_enter_flogi(rdata);
  337. mutex_unlock(&rdata->rp_mutex);
  338. } else {
  339. mutex_unlock(&rdata->rp_mutex);
  340. FC_RPORT_DBG(rdata, "work delete\n");
  341. mutex_lock(&lport->disc.disc_mutex);
  342. list_del_rcu(&rdata->peers);
  343. mutex_unlock(&lport->disc.disc_mutex);
  344. kref_put(&rdata->kref, fc_rport_destroy);
  345. }
  346. } else {
  347. /*
  348. * Re-open for events. Reissue READY event if ready.
  349. */
  350. rdata->event = RPORT_EV_NONE;
  351. if (rdata->rp_state == RPORT_ST_READY) {
  352. FC_RPORT_DBG(rdata, "work reopen\n");
  353. fc_rport_enter_ready(rdata);
  354. }
  355. mutex_unlock(&rdata->rp_mutex);
  356. }
  357. break;
  358. default:
  359. mutex_unlock(&rdata->rp_mutex);
  360. break;
  361. }
  362. kref_put(&rdata->kref, fc_rport_destroy);
  363. }
  364. /**
  365. * fc_rport_login() - Start the remote port login state machine
  366. * @rdata: The remote port to be logged in to
  367. *
  368. * Initiates the RP state machine. It is called from the LP module.
  369. * This function will issue the following commands to the N_Port
  370. * identified by the FC ID provided.
  371. *
  372. * - PLOGI
  373. * - PRLI
  374. * - RTV
  375. *
  376. * Locking Note: Called without the rport lock held. This
  377. * function will hold the rport lock, call an _enter_*
  378. * function and then unlock the rport.
  379. *
  380. * This indicates the intent to be logged into the remote port.
  381. * If it appears we are already logged in, ADISC is used to verify
  382. * the setup.
  383. */
  384. int fc_rport_login(struct fc_rport_priv *rdata)
  385. {
  386. mutex_lock(&rdata->rp_mutex);
  387. if (rdata->flags & FC_RP_STARTED) {
  388. FC_RPORT_DBG(rdata, "port already started\n");
  389. mutex_unlock(&rdata->rp_mutex);
  390. return 0;
  391. }
  392. rdata->flags |= FC_RP_STARTED;
  393. switch (rdata->rp_state) {
  394. case RPORT_ST_READY:
  395. FC_RPORT_DBG(rdata, "ADISC port\n");
  396. fc_rport_enter_adisc(rdata);
  397. break;
  398. case RPORT_ST_DELETE:
  399. FC_RPORT_DBG(rdata, "Restart deleted port\n");
  400. break;
  401. case RPORT_ST_INIT:
  402. FC_RPORT_DBG(rdata, "Login to port\n");
  403. fc_rport_enter_flogi(rdata);
  404. break;
  405. default:
  406. FC_RPORT_DBG(rdata, "Login in progress, state %s\n",
  407. fc_rport_state(rdata));
  408. break;
  409. }
  410. mutex_unlock(&rdata->rp_mutex);
  411. return 0;
  412. }
  413. EXPORT_SYMBOL(fc_rport_login);
  414. /**
  415. * fc_rport_enter_delete() - Schedule a remote port to be deleted
  416. * @rdata: The remote port to be deleted
  417. * @event: The event to report as the reason for deletion
  418. *
  419. * Allow state change into DELETE only once.
  420. *
  421. * Call queue_work only if there's no event already pending.
  422. * Set the new event so that the old pending event will not occur.
  423. * Since we have the mutex, even if fc_rport_work() is already started,
  424. * it'll see the new event.
  425. *
  426. * Reference counting: does not modify kref
  427. */
  428. static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
  429. enum fc_rport_event event)
  430. {
  431. lockdep_assert_held(&rdata->rp_mutex);
  432. if (rdata->rp_state == RPORT_ST_DELETE)
  433. return;
  434. FC_RPORT_DBG(rdata, "Delete port\n");
  435. fc_rport_state_enter(rdata, RPORT_ST_DELETE);
  436. if (rdata->event == RPORT_EV_NONE) {
  437. kref_get(&rdata->kref);
  438. if (!queue_work(rport_event_queue, &rdata->event_work))
  439. kref_put(&rdata->kref, fc_rport_destroy);
  440. }
  441. rdata->event = event;
  442. }
  443. /**
  444. * fc_rport_logoff() - Logoff and remove a remote port
  445. * @rdata: The remote port to be logged off of
  446. *
  447. * Locking Note: Called without the rport lock held. This
  448. * function will hold the rport lock, call an _enter_*
  449. * function and then unlock the rport.
  450. */
  451. int fc_rport_logoff(struct fc_rport_priv *rdata)
  452. {
  453. struct fc_lport *lport = rdata->local_port;
  454. u32 port_id = rdata->ids.port_id;
  455. mutex_lock(&rdata->rp_mutex);
  456. FC_RPORT_DBG(rdata, "Remove port\n");
  457. rdata->flags &= ~FC_RP_STARTED;
  458. if (rdata->rp_state == RPORT_ST_DELETE) {
  459. FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
  460. goto out;
  461. }
  462. /*
  463. * FC-LS states:
  464. * To explicitly Logout, the initiating Nx_Port shall terminate
  465. * other open Sequences that it initiated with the destination
  466. * Nx_Port prior to performing Logout.
  467. */
  468. lport->tt.exch_mgr_reset(lport, 0, port_id);
  469. lport->tt.exch_mgr_reset(lport, port_id, 0);
  470. fc_rport_enter_logo(rdata);
  471. /*
  472. * Change the state to Delete so that we discard
  473. * the response.
  474. */
  475. fc_rport_enter_delete(rdata, RPORT_EV_STOP);
  476. out:
  477. mutex_unlock(&rdata->rp_mutex);
  478. return 0;
  479. }
  480. EXPORT_SYMBOL(fc_rport_logoff);
  481. /**
  482. * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
  483. * @rdata: The remote port that is ready
  484. *
  485. * Reference counting: schedules workqueue, does not modify kref
  486. */
  487. static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
  488. {
  489. lockdep_assert_held(&rdata->rp_mutex);
  490. fc_rport_state_enter(rdata, RPORT_ST_READY);
  491. FC_RPORT_DBG(rdata, "Port is Ready\n");
  492. kref_get(&rdata->kref);
  493. if (rdata->event == RPORT_EV_NONE &&
  494. !queue_work(rport_event_queue, &rdata->event_work))
  495. kref_put(&rdata->kref, fc_rport_destroy);
  496. rdata->event = RPORT_EV_READY;
  497. }
  498. /**
  499. * fc_rport_timeout() - Handler for the retry_work timer
  500. * @work: Handle to the remote port that has timed out
  501. *
  502. * Locking Note: Called without the rport lock held. This
  503. * function will hold the rport lock, call an _enter_*
  504. * function and then unlock the rport.
  505. *
  506. * Reference counting: Drops kref on return.
  507. */
  508. static void fc_rport_timeout(struct work_struct *work)
  509. {
  510. struct fc_rport_priv *rdata =
  511. container_of(work, struct fc_rport_priv, retry_work.work);
  512. mutex_lock(&rdata->rp_mutex);
  513. FC_RPORT_DBG(rdata, "Port timeout, state %s\n", fc_rport_state(rdata));
  514. switch (rdata->rp_state) {
  515. case RPORT_ST_FLOGI:
  516. fc_rport_enter_flogi(rdata);
  517. break;
  518. case RPORT_ST_PLOGI:
  519. fc_rport_enter_plogi(rdata);
  520. break;
  521. case RPORT_ST_PRLI:
  522. fc_rport_enter_prli(rdata);
  523. break;
  524. case RPORT_ST_RTV:
  525. fc_rport_enter_rtv(rdata);
  526. break;
  527. case RPORT_ST_ADISC:
  528. fc_rport_enter_adisc(rdata);
  529. break;
  530. case RPORT_ST_PLOGI_WAIT:
  531. case RPORT_ST_READY:
  532. case RPORT_ST_INIT:
  533. case RPORT_ST_DELETE:
  534. break;
  535. }
  536. mutex_unlock(&rdata->rp_mutex);
  537. kref_put(&rdata->kref, fc_rport_destroy);
  538. }
  539. /**
  540. * fc_rport_error() - Error handler, called once retries have been exhausted
  541. * @rdata: The remote port the error is happened on
  542. * @err: The error code
  543. *
  544. * Reference counting: does not modify kref
  545. */
  546. static void fc_rport_error(struct fc_rport_priv *rdata, int err)
  547. {
  548. struct fc_lport *lport = rdata->local_port;
  549. lockdep_assert_held(&rdata->rp_mutex);
  550. FC_RPORT_DBG(rdata, "Error %d in state %s, retries %d\n",
  551. -err, fc_rport_state(rdata), rdata->retries);
  552. switch (rdata->rp_state) {
  553. case RPORT_ST_FLOGI:
  554. rdata->flags &= ~FC_RP_STARTED;
  555. fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
  556. break;
  557. case RPORT_ST_PLOGI:
  558. if (lport->point_to_multipoint) {
  559. rdata->flags &= ~FC_RP_STARTED;
  560. fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
  561. } else
  562. fc_rport_enter_logo(rdata);
  563. break;
  564. case RPORT_ST_RTV:
  565. fc_rport_enter_ready(rdata);
  566. break;
  567. case RPORT_ST_PRLI:
  568. fc_rport_enter_plogi(rdata);
  569. break;
  570. case RPORT_ST_ADISC:
  571. fc_rport_enter_logo(rdata);
  572. break;
  573. case RPORT_ST_PLOGI_WAIT:
  574. case RPORT_ST_DELETE:
  575. case RPORT_ST_READY:
  576. case RPORT_ST_INIT:
  577. break;
  578. }
  579. }
  580. /**
  581. * fc_rport_error_retry() - Handler for remote port state retries
  582. * @rdata: The remote port whose state is to be retried
  583. * @err: The error code
  584. *
  585. * If the error was an exchange timeout retry immediately,
  586. * otherwise wait for E_D_TOV.
  587. *
  588. * Reference counting: increments kref when scheduling retry_work
  589. */
  590. static void fc_rport_error_retry(struct fc_rport_priv *rdata, int err)
  591. {
  592. unsigned long delay = msecs_to_jiffies(rdata->e_d_tov);
  593. lockdep_assert_held(&rdata->rp_mutex);
  594. /* make sure this isn't an FC_EX_CLOSED error, never retry those */
  595. if (err == -FC_EX_CLOSED)
  596. goto out;
  597. if (rdata->retries < rdata->local_port->max_rport_retry_count) {
  598. FC_RPORT_DBG(rdata, "Error %d in state %s, retrying\n",
  599. err, fc_rport_state(rdata));
  600. rdata->retries++;
  601. /* no additional delay on exchange timeouts */
  602. if (err == -FC_EX_TIMEOUT)
  603. delay = 0;
  604. kref_get(&rdata->kref);
  605. if (!schedule_delayed_work(&rdata->retry_work, delay))
  606. kref_put(&rdata->kref, fc_rport_destroy);
  607. return;
  608. }
  609. out:
  610. fc_rport_error(rdata, err);
  611. }
  612. /**
  613. * fc_rport_login_complete() - Handle parameters and completion of p-mp login.
  614. * @rdata: The remote port which we logged into or which logged into us.
  615. * @fp: The FLOGI or PLOGI request or response frame
  616. *
  617. * Returns non-zero error if a problem is detected with the frame.
  618. * Does not free the frame.
  619. *
  620. * This is only used in point-to-multipoint mode for FIP currently.
  621. */
  622. static int fc_rport_login_complete(struct fc_rport_priv *rdata,
  623. struct fc_frame *fp)
  624. {
  625. struct fc_lport *lport = rdata->local_port;
  626. struct fc_els_flogi *flogi;
  627. unsigned int e_d_tov;
  628. u16 csp_flags;
  629. flogi = fc_frame_payload_get(fp, sizeof(*flogi));
  630. if (!flogi)
  631. return -EINVAL;
  632. csp_flags = ntohs(flogi->fl_csp.sp_features);
  633. if (fc_frame_payload_op(fp) == ELS_FLOGI) {
  634. if (csp_flags & FC_SP_FT_FPORT) {
  635. FC_RPORT_DBG(rdata, "Fabric bit set in FLOGI\n");
  636. return -EINVAL;
  637. }
  638. } else {
  639. /*
  640. * E_D_TOV is not valid on an incoming FLOGI request.
  641. */
  642. e_d_tov = ntohl(flogi->fl_csp.sp_e_d_tov);
  643. if (csp_flags & FC_SP_FT_EDTR)
  644. e_d_tov /= 1000000;
  645. if (e_d_tov > rdata->e_d_tov)
  646. rdata->e_d_tov = e_d_tov;
  647. }
  648. rdata->maxframe_size = fc_plogi_get_maxframe(flogi, lport->mfs);
  649. return 0;
  650. }
  651. /**
  652. * fc_rport_flogi_resp() - Handle response to FLOGI request for p-mp mode
  653. * @sp: The sequence that the FLOGI was on
  654. * @fp: The FLOGI response frame
  655. * @rp_arg: The remote port that received the FLOGI response
  656. */
  657. static void fc_rport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
  658. void *rp_arg)
  659. {
  660. struct fc_rport_priv *rdata = rp_arg;
  661. struct fc_lport *lport = rdata->local_port;
  662. struct fc_els_flogi *flogi;
  663. unsigned int r_a_tov;
  664. u8 opcode;
  665. int err = 0;
  666. FC_RPORT_DBG(rdata, "Received a FLOGI %s\n",
  667. IS_ERR(fp) ? "error" : fc_els_resp_type(fp));
  668. if (fp == ERR_PTR(-FC_EX_CLOSED))
  669. goto put;
  670. mutex_lock(&rdata->rp_mutex);
  671. if (rdata->rp_state != RPORT_ST_FLOGI) {
  672. FC_RPORT_DBG(rdata, "Received a FLOGI response, but in state "
  673. "%s\n", fc_rport_state(rdata));
  674. if (IS_ERR(fp))
  675. goto err;
  676. goto out;
  677. }
  678. if (IS_ERR(fp)) {
  679. fc_rport_error(rdata, PTR_ERR(fp));
  680. goto err;
  681. }
  682. opcode = fc_frame_payload_op(fp);
  683. if (opcode == ELS_LS_RJT) {
  684. struct fc_els_ls_rjt *rjt;
  685. rjt = fc_frame_payload_get(fp, sizeof(*rjt));
  686. FC_RPORT_DBG(rdata, "FLOGI ELS rejected, reason %x expl %x\n",
  687. rjt->er_reason, rjt->er_explan);
  688. err = -FC_EX_ELS_RJT;
  689. goto bad;
  690. } else if (opcode != ELS_LS_ACC) {
  691. FC_RPORT_DBG(rdata, "FLOGI ELS invalid opcode %x\n", opcode);
  692. err = -FC_EX_ELS_RJT;
  693. goto bad;
  694. }
  695. if (fc_rport_login_complete(rdata, fp)) {
  696. FC_RPORT_DBG(rdata, "FLOGI failed, no login\n");
  697. err = -FC_EX_INV_LOGIN;
  698. goto bad;
  699. }
  700. flogi = fc_frame_payload_get(fp, sizeof(*flogi));
  701. if (!flogi) {
  702. err = -FC_EX_ALLOC_ERR;
  703. goto bad;
  704. }
  705. r_a_tov = ntohl(flogi->fl_csp.sp_r_a_tov);
  706. if (r_a_tov > rdata->r_a_tov)
  707. rdata->r_a_tov = r_a_tov;
  708. if (rdata->ids.port_name < lport->wwpn)
  709. fc_rport_enter_plogi(rdata);
  710. else
  711. fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
  712. out:
  713. fc_frame_free(fp);
  714. err:
  715. mutex_unlock(&rdata->rp_mutex);
  716. put:
  717. kref_put(&rdata->kref, fc_rport_destroy);
  718. return;
  719. bad:
  720. FC_RPORT_DBG(rdata, "Bad FLOGI response\n");
  721. fc_rport_error_retry(rdata, err);
  722. goto out;
  723. }
  724. /**
  725. * fc_rport_enter_flogi() - Send a FLOGI request to the remote port for p-mp
  726. * @rdata: The remote port to send a FLOGI to
  727. *
  728. * Reference counting: increments kref when sending ELS
  729. */
  730. static void fc_rport_enter_flogi(struct fc_rport_priv *rdata)
  731. {
  732. struct fc_lport *lport = rdata->local_port;
  733. struct fc_frame *fp;
  734. lockdep_assert_held(&rdata->rp_mutex);
  735. if (!lport->point_to_multipoint)
  736. return fc_rport_enter_plogi(rdata);
  737. FC_RPORT_DBG(rdata, "Entered FLOGI state from %s state\n",
  738. fc_rport_state(rdata));
  739. fc_rport_state_enter(rdata, RPORT_ST_FLOGI);
  740. fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
  741. if (!fp)
  742. return fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
  743. kref_get(&rdata->kref);
  744. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_FLOGI,
  745. fc_rport_flogi_resp, rdata,
  746. 2 * lport->r_a_tov)) {
  747. fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
  748. kref_put(&rdata->kref, fc_rport_destroy);
  749. }
  750. }
  751. /**
  752. * fc_rport_recv_flogi_req() - Handle Fabric Login (FLOGI) request in p-mp mode
  753. * @lport: The local port that received the PLOGI request
  754. * @rx_fp: The PLOGI request frame
  755. *
  756. * Reference counting: drops kref on return
  757. */
  758. static void fc_rport_recv_flogi_req(struct fc_lport *lport,
  759. struct fc_frame *rx_fp)
  760. {
  761. struct fc_els_flogi *flp;
  762. struct fc_rport_priv *rdata;
  763. struct fc_frame *fp = rx_fp;
  764. struct fc_seq_els_data rjt_data;
  765. u32 sid;
  766. sid = fc_frame_sid(fp);
  767. FC_RPORT_ID_DBG(lport, sid, "Received FLOGI request\n");
  768. if (!lport->point_to_multipoint) {
  769. rjt_data.reason = ELS_RJT_UNSUP;
  770. rjt_data.explan = ELS_EXPL_NONE;
  771. goto reject;
  772. }
  773. flp = fc_frame_payload_get(fp, sizeof(*flp));
  774. if (!flp) {
  775. rjt_data.reason = ELS_RJT_LOGIC;
  776. rjt_data.explan = ELS_EXPL_INV_LEN;
  777. goto reject;
  778. }
  779. rdata = fc_rport_lookup(lport, sid);
  780. if (!rdata) {
  781. rjt_data.reason = ELS_RJT_FIP;
  782. rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
  783. goto reject;
  784. }
  785. mutex_lock(&rdata->rp_mutex);
  786. FC_RPORT_DBG(rdata, "Received FLOGI in %s state\n",
  787. fc_rport_state(rdata));
  788. switch (rdata->rp_state) {
  789. case RPORT_ST_INIT:
  790. /*
  791. * If received the FLOGI request on RPORT which is INIT state
  792. * (means not transition to FLOGI either fc_rport timeout
  793. * function didn;t trigger or this end hasn;t received
  794. * beacon yet from other end. In that case only, allow RPORT
  795. * state machine to continue, otherwise fall through which
  796. * causes the code to send reject response.
  797. * NOTE; Not checking for FIP->state such as VNMP_UP or
  798. * VNMP_CLAIM because if FIP state is not one of those,
  799. * RPORT wouldn;t have created and 'rport_lookup' would have
  800. * failed anyway in that case.
  801. */
  802. break;
  803. case RPORT_ST_DELETE:
  804. mutex_unlock(&rdata->rp_mutex);
  805. rjt_data.reason = ELS_RJT_FIP;
  806. rjt_data.explan = ELS_EXPL_NOT_NEIGHBOR;
  807. goto reject_put;
  808. case RPORT_ST_FLOGI:
  809. case RPORT_ST_PLOGI_WAIT:
  810. case RPORT_ST_PLOGI:
  811. break;
  812. case RPORT_ST_PRLI:
  813. case RPORT_ST_RTV:
  814. case RPORT_ST_READY:
  815. case RPORT_ST_ADISC:
  816. /*
  817. * Set the remote port to be deleted and to then restart.
  818. * This queues work to be sure exchanges are reset.
  819. */
  820. fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
  821. mutex_unlock(&rdata->rp_mutex);
  822. rjt_data.reason = ELS_RJT_BUSY;
  823. rjt_data.explan = ELS_EXPL_NONE;
  824. goto reject_put;
  825. }
  826. if (fc_rport_login_complete(rdata, fp)) {
  827. mutex_unlock(&rdata->rp_mutex);
  828. rjt_data.reason = ELS_RJT_LOGIC;
  829. rjt_data.explan = ELS_EXPL_NONE;
  830. goto reject_put;
  831. }
  832. fp = fc_frame_alloc(lport, sizeof(*flp));
  833. if (!fp)
  834. goto out;
  835. fc_flogi_fill(lport, fp);
  836. flp = fc_frame_payload_get(fp, sizeof(*flp));
  837. flp->fl_cmd = ELS_LS_ACC;
  838. fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
  839. lport->tt.frame_send(lport, fp);
  840. /*
  841. * Do not proceed with the state machine if our
  842. * FLOGI has crossed with an FLOGI from the
  843. * remote port; wait for the FLOGI response instead.
  844. */
  845. if (rdata->rp_state != RPORT_ST_FLOGI) {
  846. if (rdata->ids.port_name < lport->wwpn)
  847. fc_rport_enter_plogi(rdata);
  848. else
  849. fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
  850. }
  851. out:
  852. mutex_unlock(&rdata->rp_mutex);
  853. kref_put(&rdata->kref, fc_rport_destroy);
  854. fc_frame_free(rx_fp);
  855. return;
  856. reject_put:
  857. kref_put(&rdata->kref, fc_rport_destroy);
  858. reject:
  859. fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
  860. fc_frame_free(rx_fp);
  861. }
  862. /**
  863. * fc_rport_plogi_resp() - Handler for ELS PLOGI responses
  864. * @sp: The sequence the PLOGI is on
  865. * @fp: The PLOGI response frame
  866. * @rdata_arg: The remote port that sent the PLOGI response
  867. *
  868. * Locking Note: This function will be called without the rport lock
  869. * held, but it will lock, call an _enter_* function or fc_rport_error
  870. * and then unlock the rport.
  871. */
  872. static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
  873. void *rdata_arg)
  874. {
  875. struct fc_rport_priv *rdata = rdata_arg;
  876. struct fc_lport *lport = rdata->local_port;
  877. struct fc_els_flogi *plp = NULL;
  878. u16 csp_seq;
  879. u16 cssp_seq;
  880. u8 op;
  881. FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
  882. if (fp == ERR_PTR(-FC_EX_CLOSED))
  883. goto put;
  884. mutex_lock(&rdata->rp_mutex);
  885. if (rdata->rp_state != RPORT_ST_PLOGI) {
  886. FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
  887. "%s\n", fc_rport_state(rdata));
  888. if (IS_ERR(fp))
  889. goto err;
  890. goto out;
  891. }
  892. if (IS_ERR(fp)) {
  893. fc_rport_error_retry(rdata, PTR_ERR(fp));
  894. goto err;
  895. }
  896. op = fc_frame_payload_op(fp);
  897. if (op == ELS_LS_ACC &&
  898. (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
  899. rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
  900. rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
  901. /* save plogi response sp_features for further reference */
  902. rdata->sp_features = ntohs(plp->fl_csp.sp_features);
  903. if (lport->point_to_multipoint)
  904. fc_rport_login_complete(rdata, fp);
  905. csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
  906. cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
  907. if (cssp_seq < csp_seq)
  908. csp_seq = cssp_seq;
  909. rdata->max_seq = csp_seq;
  910. rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
  911. fc_rport_enter_prli(rdata);
  912. } else {
  913. struct fc_els_ls_rjt *rjt;
  914. rjt = fc_frame_payload_get(fp, sizeof(*rjt));
  915. if (!rjt)
  916. FC_RPORT_DBG(rdata, "PLOGI bad response\n");
  917. else
  918. FC_RPORT_DBG(rdata, "PLOGI ELS rejected, reason %x expl %x\n",
  919. rjt->er_reason, rjt->er_explan);
  920. fc_rport_error_retry(rdata, -FC_EX_ELS_RJT);
  921. }
  922. out:
  923. fc_frame_free(fp);
  924. err:
  925. mutex_unlock(&rdata->rp_mutex);
  926. put:
  927. kref_put(&rdata->kref, fc_rport_destroy);
  928. }
  929. static bool
  930. fc_rport_compatible_roles(struct fc_lport *lport, struct fc_rport_priv *rdata)
  931. {
  932. if (rdata->ids.roles == FC_PORT_ROLE_UNKNOWN)
  933. return true;
  934. if ((rdata->ids.roles & FC_PORT_ROLE_FCP_TARGET) &&
  935. (lport->service_params & FCP_SPPF_INIT_FCN))
  936. return true;
  937. if ((rdata->ids.roles & FC_PORT_ROLE_FCP_INITIATOR) &&
  938. (lport->service_params & FCP_SPPF_TARG_FCN))
  939. return true;
  940. return false;
  941. }
  942. /**
  943. * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
  944. * @rdata: The remote port to send a PLOGI to
  945. *
  946. * Reference counting: increments kref when sending ELS
  947. */
  948. static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
  949. {
  950. struct fc_lport *lport = rdata->local_port;
  951. struct fc_frame *fp;
  952. lockdep_assert_held(&rdata->rp_mutex);
  953. if (!fc_rport_compatible_roles(lport, rdata)) {
  954. FC_RPORT_DBG(rdata, "PLOGI suppressed for incompatible role\n");
  955. fc_rport_state_enter(rdata, RPORT_ST_PLOGI_WAIT);
  956. return;
  957. }
  958. FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
  959. fc_rport_state(rdata));
  960. fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
  961. rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
  962. fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
  963. if (!fp) {
  964. FC_RPORT_DBG(rdata, "%s frame alloc failed\n", __func__);
  965. fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
  966. return;
  967. }
  968. rdata->e_d_tov = lport->e_d_tov;
  969. kref_get(&rdata->kref);
  970. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
  971. fc_rport_plogi_resp, rdata,
  972. 2 * lport->r_a_tov)) {
  973. fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
  974. kref_put(&rdata->kref, fc_rport_destroy);
  975. }
  976. }
  977. /**
  978. * fc_rport_prli_resp() - Process Login (PRLI) response handler
  979. * @sp: The sequence the PRLI response was on
  980. * @fp: The PRLI response frame
  981. * @rdata_arg: The remote port that sent the PRLI response
  982. *
  983. * Locking Note: This function will be called without the rport lock
  984. * held, but it will lock, call an _enter_* function or fc_rport_error
  985. * and then unlock the rport.
  986. */
  987. static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
  988. void *rdata_arg)
  989. {
  990. struct fc_rport_priv *rdata = rdata_arg;
  991. struct {
  992. struct fc_els_prli prli;
  993. struct fc_els_spp spp;
  994. } *pp;
  995. struct fc_els_spp temp_spp;
  996. struct fc_els_ls_rjt *rjt;
  997. struct fc4_prov *prov;
  998. u32 roles = FC_RPORT_ROLE_UNKNOWN;
  999. u32 fcp_parm = 0;
  1000. u8 op;
  1001. enum fc_els_spp_resp resp_code;
  1002. FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
  1003. if (fp == ERR_PTR(-FC_EX_CLOSED))
  1004. goto put;
  1005. mutex_lock(&rdata->rp_mutex);
  1006. if (rdata->rp_state != RPORT_ST_PRLI) {
  1007. FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
  1008. "%s\n", fc_rport_state(rdata));
  1009. if (IS_ERR(fp))
  1010. goto err;
  1011. goto out;
  1012. }
  1013. if (IS_ERR(fp)) {
  1014. fc_rport_error_retry(rdata, PTR_ERR(fp));
  1015. goto err;
  1016. }
  1017. /* reinitialize remote port roles */
  1018. rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
  1019. op = fc_frame_payload_op(fp);
  1020. if (op == ELS_LS_ACC) {
  1021. pp = fc_frame_payload_get(fp, sizeof(*pp));
  1022. if (!pp) {
  1023. fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
  1024. goto out;
  1025. }
  1026. resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
  1027. FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
  1028. pp->spp.spp_flags, pp->spp.spp_type);
  1029. rdata->spp_type = pp->spp.spp_type;
  1030. if (resp_code != FC_SPP_RESP_ACK) {
  1031. if (resp_code == FC_SPP_RESP_CONF)
  1032. fc_rport_error(rdata, -FC_EX_SEQ_ERR);
  1033. else
  1034. fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
  1035. goto out;
  1036. }
  1037. if (pp->prli.prli_spp_len < sizeof(pp->spp)) {
  1038. fc_rport_error_retry(rdata, -FC_EX_SEQ_ERR);
  1039. goto out;
  1040. }
  1041. fcp_parm = ntohl(pp->spp.spp_params);
  1042. if (fcp_parm & FCP_SPPF_RETRY)
  1043. rdata->flags |= FC_RP_FLAGS_RETRY;
  1044. if (fcp_parm & FCP_SPPF_CONF_COMPL)
  1045. rdata->flags |= FC_RP_FLAGS_CONF_REQ;
  1046. /*
  1047. * Call prli provider if we should act as a target
  1048. */
  1049. if (rdata->spp_type < FC_FC4_PROV_SIZE) {
  1050. prov = fc_passive_prov[rdata->spp_type];
  1051. if (prov) {
  1052. memset(&temp_spp, 0, sizeof(temp_spp));
  1053. prov->prli(rdata, pp->prli.prli_spp_len,
  1054. &pp->spp, &temp_spp);
  1055. }
  1056. }
  1057. /*
  1058. * Check if the image pair could be established
  1059. */
  1060. if (rdata->spp_type != FC_TYPE_FCP ||
  1061. !(pp->spp.spp_flags & FC_SPP_EST_IMG_PAIR)) {
  1062. /*
  1063. * Nope; we can't use this port as a target.
  1064. */
  1065. fcp_parm &= ~FCP_SPPF_TARG_FCN;
  1066. }
  1067. rdata->supported_classes = FC_COS_CLASS3;
  1068. if (fcp_parm & FCP_SPPF_INIT_FCN)
  1069. roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  1070. if (fcp_parm & FCP_SPPF_TARG_FCN)
  1071. roles |= FC_RPORT_ROLE_FCP_TARGET;
  1072. rdata->ids.roles = roles;
  1073. fc_rport_enter_rtv(rdata);
  1074. } else {
  1075. rjt = fc_frame_payload_get(fp, sizeof(*rjt));
  1076. if (!rjt)
  1077. FC_RPORT_DBG(rdata, "PRLI bad response\n");
  1078. else {
  1079. FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
  1080. rjt->er_reason, rjt->er_explan);
  1081. if (rjt->er_reason == ELS_RJT_UNAB &&
  1082. rjt->er_explan == ELS_EXPL_PLOGI_REQD) {
  1083. fc_rport_enter_plogi(rdata);
  1084. goto out;
  1085. }
  1086. }
  1087. fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
  1088. }
  1089. out:
  1090. fc_frame_free(fp);
  1091. err:
  1092. mutex_unlock(&rdata->rp_mutex);
  1093. put:
  1094. kref_put(&rdata->kref, fc_rport_destroy);
  1095. }
  1096. /**
  1097. * fc_rport_enter_prli() - Send Process Login (PRLI) request
  1098. * @rdata: The remote port to send the PRLI request to
  1099. *
  1100. * Reference counting: increments kref when sending ELS
  1101. */
  1102. static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
  1103. {
  1104. struct fc_lport *lport = rdata->local_port;
  1105. struct {
  1106. struct fc_els_prli prli;
  1107. struct fc_els_spp spp;
  1108. } *pp;
  1109. struct fc_frame *fp;
  1110. struct fc4_prov *prov;
  1111. lockdep_assert_held(&rdata->rp_mutex);
  1112. /*
  1113. * If the rport is one of the well known addresses
  1114. * we skip PRLI and RTV and go straight to READY.
  1115. */
  1116. if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
  1117. fc_rport_enter_ready(rdata);
  1118. return;
  1119. }
  1120. /*
  1121. * And if the local port does not support the initiator function
  1122. * there's no need to send a PRLI, either.
  1123. */
  1124. if (!(lport->service_params & FCP_SPPF_INIT_FCN)) {
  1125. fc_rport_enter_ready(rdata);
  1126. return;
  1127. }
  1128. FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
  1129. fc_rport_state(rdata));
  1130. fc_rport_state_enter(rdata, RPORT_ST_PRLI);
  1131. fp = fc_frame_alloc(lport, sizeof(*pp));
  1132. if (!fp) {
  1133. fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
  1134. return;
  1135. }
  1136. fc_prli_fill(lport, fp);
  1137. prov = fc_passive_prov[FC_TYPE_FCP];
  1138. if (prov) {
  1139. pp = fc_frame_payload_get(fp, sizeof(*pp));
  1140. prov->prli(rdata, sizeof(pp->spp), NULL, &pp->spp);
  1141. }
  1142. fc_fill_fc_hdr(fp, FC_RCTL_ELS_REQ, rdata->ids.port_id,
  1143. fc_host_port_id(lport->host), FC_TYPE_ELS,
  1144. FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
  1145. kref_get(&rdata->kref);
  1146. if (!fc_exch_seq_send(lport, fp, fc_rport_prli_resp,
  1147. NULL, rdata, 2 * lport->r_a_tov)) {
  1148. fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
  1149. kref_put(&rdata->kref, fc_rport_destroy);
  1150. }
  1151. }
  1152. /**
  1153. * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
  1154. * @sp: The sequence the RTV was on
  1155. * @fp: The RTV response frame
  1156. * @rdata_arg: The remote port that sent the RTV response
  1157. *
  1158. * Many targets don't seem to support this.
  1159. *
  1160. * Locking Note: This function will be called without the rport lock
  1161. * held, but it will lock, call an _enter_* function or fc_rport_error
  1162. * and then unlock the rport.
  1163. */
  1164. static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
  1165. void *rdata_arg)
  1166. {
  1167. struct fc_rport_priv *rdata = rdata_arg;
  1168. u8 op;
  1169. FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
  1170. if (fp == ERR_PTR(-FC_EX_CLOSED))
  1171. goto put;
  1172. mutex_lock(&rdata->rp_mutex);
  1173. if (rdata->rp_state != RPORT_ST_RTV) {
  1174. FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
  1175. "%s\n", fc_rport_state(rdata));
  1176. if (IS_ERR(fp))
  1177. goto err;
  1178. goto out;
  1179. }
  1180. if (IS_ERR(fp)) {
  1181. fc_rport_error(rdata, PTR_ERR(fp));
  1182. goto err;
  1183. }
  1184. op = fc_frame_payload_op(fp);
  1185. if (op == ELS_LS_ACC) {
  1186. struct fc_els_rtv_acc *rtv;
  1187. u32 toq;
  1188. u32 tov;
  1189. rtv = fc_frame_payload_get(fp, sizeof(*rtv));
  1190. if (rtv) {
  1191. toq = ntohl(rtv->rtv_toq);
  1192. tov = ntohl(rtv->rtv_r_a_tov);
  1193. if (tov == 0)
  1194. tov = 1;
  1195. if (tov > rdata->r_a_tov)
  1196. rdata->r_a_tov = tov;
  1197. tov = ntohl(rtv->rtv_e_d_tov);
  1198. if (toq & FC_ELS_RTV_EDRES)
  1199. tov /= 1000000;
  1200. if (tov == 0)
  1201. tov = 1;
  1202. if (tov > rdata->e_d_tov)
  1203. rdata->e_d_tov = tov;
  1204. }
  1205. }
  1206. fc_rport_enter_ready(rdata);
  1207. out:
  1208. fc_frame_free(fp);
  1209. err:
  1210. mutex_unlock(&rdata->rp_mutex);
  1211. put:
  1212. kref_put(&rdata->kref, fc_rport_destroy);
  1213. }
  1214. /**
  1215. * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
  1216. * @rdata: The remote port to send the RTV request to
  1217. *
  1218. * Reference counting: increments kref when sending ELS
  1219. */
  1220. static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
  1221. {
  1222. struct fc_frame *fp;
  1223. struct fc_lport *lport = rdata->local_port;
  1224. lockdep_assert_held(&rdata->rp_mutex);
  1225. FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
  1226. fc_rport_state(rdata));
  1227. fc_rport_state_enter(rdata, RPORT_ST_RTV);
  1228. fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
  1229. if (!fp) {
  1230. fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
  1231. return;
  1232. }
  1233. kref_get(&rdata->kref);
  1234. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
  1235. fc_rport_rtv_resp, rdata,
  1236. 2 * lport->r_a_tov)) {
  1237. fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
  1238. kref_put(&rdata->kref, fc_rport_destroy);
  1239. }
  1240. }
  1241. /**
  1242. * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
  1243. * @rdata: The remote port that sent the RTV request
  1244. * @in_fp: The RTV request frame
  1245. */
  1246. static void fc_rport_recv_rtv_req(struct fc_rport_priv *rdata,
  1247. struct fc_frame *in_fp)
  1248. {
  1249. struct fc_lport *lport = rdata->local_port;
  1250. struct fc_frame *fp;
  1251. struct fc_els_rtv_acc *rtv;
  1252. struct fc_seq_els_data rjt_data;
  1253. lockdep_assert_held(&rdata->rp_mutex);
  1254. lockdep_assert_held(&lport->lp_mutex);
  1255. FC_RPORT_DBG(rdata, "Received RTV request\n");
  1256. fp = fc_frame_alloc(lport, sizeof(*rtv));
  1257. if (!fp) {
  1258. rjt_data.reason = ELS_RJT_UNAB;
  1259. rjt_data.explan = ELS_EXPL_INSUF_RES;
  1260. fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
  1261. goto drop;
  1262. }
  1263. rtv = fc_frame_payload_get(fp, sizeof(*rtv));
  1264. rtv->rtv_cmd = ELS_LS_ACC;
  1265. rtv->rtv_r_a_tov = htonl(lport->r_a_tov);
  1266. rtv->rtv_e_d_tov = htonl(lport->e_d_tov);
  1267. rtv->rtv_toq = 0;
  1268. fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
  1269. lport->tt.frame_send(lport, fp);
  1270. drop:
  1271. fc_frame_free(in_fp);
  1272. }
  1273. /**
  1274. * fc_rport_logo_resp() - Handler for logout (LOGO) responses
  1275. * @sp: The sequence the LOGO was on
  1276. * @fp: The LOGO response frame
  1277. * @rdata_arg: The remote port
  1278. */
  1279. static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
  1280. void *rdata_arg)
  1281. {
  1282. struct fc_rport_priv *rdata = rdata_arg;
  1283. struct fc_lport *lport = rdata->local_port;
  1284. FC_RPORT_ID_DBG(lport, fc_seq_exch(sp)->did,
  1285. "Received a LOGO %s\n", fc_els_resp_type(fp));
  1286. if (!IS_ERR(fp))
  1287. fc_frame_free(fp);
  1288. kref_put(&rdata->kref, fc_rport_destroy);
  1289. }
  1290. /**
  1291. * fc_rport_enter_logo() - Send a logout (LOGO) request
  1292. * @rdata: The remote port to send the LOGO request to
  1293. *
  1294. * Reference counting: increments kref when sending ELS
  1295. */
  1296. static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
  1297. {
  1298. struct fc_lport *lport = rdata->local_port;
  1299. struct fc_frame *fp;
  1300. lockdep_assert_held(&rdata->rp_mutex);
  1301. FC_RPORT_DBG(rdata, "Port sending LOGO from %s state\n",
  1302. fc_rport_state(rdata));
  1303. fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
  1304. if (!fp)
  1305. return;
  1306. kref_get(&rdata->kref);
  1307. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
  1308. fc_rport_logo_resp, rdata, 0))
  1309. kref_put(&rdata->kref, fc_rport_destroy);
  1310. }
  1311. /**
  1312. * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
  1313. * @sp: The sequence the ADISC response was on
  1314. * @fp: The ADISC response frame
  1315. * @rdata_arg: The remote port that sent the ADISC response
  1316. *
  1317. * Locking Note: This function will be called without the rport lock
  1318. * held, but it will lock, call an _enter_* function or fc_rport_error
  1319. * and then unlock the rport.
  1320. */
  1321. static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
  1322. void *rdata_arg)
  1323. {
  1324. struct fc_rport_priv *rdata = rdata_arg;
  1325. struct fc_els_adisc *adisc;
  1326. u8 op;
  1327. FC_RPORT_DBG(rdata, "Received a ADISC response\n");
  1328. if (fp == ERR_PTR(-FC_EX_CLOSED))
  1329. goto put;
  1330. mutex_lock(&rdata->rp_mutex);
  1331. if (rdata->rp_state != RPORT_ST_ADISC) {
  1332. FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
  1333. fc_rport_state(rdata));
  1334. if (IS_ERR(fp))
  1335. goto err;
  1336. goto out;
  1337. }
  1338. if (IS_ERR(fp)) {
  1339. fc_rport_error(rdata, PTR_ERR(fp));
  1340. goto err;
  1341. }
  1342. /*
  1343. * If address verification failed. Consider us logged out of the rport.
  1344. * Since the rport is still in discovery, we want to be
  1345. * logged in, so go to PLOGI state. Otherwise, go back to READY.
  1346. */
  1347. op = fc_frame_payload_op(fp);
  1348. adisc = fc_frame_payload_get(fp, sizeof(*adisc));
  1349. if (op != ELS_LS_ACC || !adisc ||
  1350. ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
  1351. get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
  1352. get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
  1353. FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
  1354. fc_rport_enter_flogi(rdata);
  1355. } else {
  1356. FC_RPORT_DBG(rdata, "ADISC OK\n");
  1357. fc_rport_enter_ready(rdata);
  1358. }
  1359. out:
  1360. fc_frame_free(fp);
  1361. err:
  1362. mutex_unlock(&rdata->rp_mutex);
  1363. put:
  1364. kref_put(&rdata->kref, fc_rport_destroy);
  1365. }
  1366. /**
  1367. * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
  1368. * @rdata: The remote port to send the ADISC request to
  1369. *
  1370. * Reference counting: increments kref when sending ELS
  1371. */
  1372. static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
  1373. {
  1374. struct fc_lport *lport = rdata->local_port;
  1375. struct fc_frame *fp;
  1376. lockdep_assert_held(&rdata->rp_mutex);
  1377. FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
  1378. fc_rport_state(rdata));
  1379. fc_rport_state_enter(rdata, RPORT_ST_ADISC);
  1380. fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
  1381. if (!fp) {
  1382. fc_rport_error_retry(rdata, -FC_EX_ALLOC_ERR);
  1383. return;
  1384. }
  1385. kref_get(&rdata->kref);
  1386. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
  1387. fc_rport_adisc_resp, rdata,
  1388. 2 * lport->r_a_tov)) {
  1389. fc_rport_error_retry(rdata, -FC_EX_XMIT_ERR);
  1390. kref_put(&rdata->kref, fc_rport_destroy);
  1391. }
  1392. }
  1393. /**
  1394. * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
  1395. * @rdata: The remote port that sent the ADISC request
  1396. * @in_fp: The ADISC request frame
  1397. */
  1398. static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
  1399. struct fc_frame *in_fp)
  1400. {
  1401. struct fc_lport *lport = rdata->local_port;
  1402. struct fc_frame *fp;
  1403. struct fc_els_adisc *adisc;
  1404. struct fc_seq_els_data rjt_data;
  1405. lockdep_assert_held(&rdata->rp_mutex);
  1406. lockdep_assert_held(&lport->lp_mutex);
  1407. FC_RPORT_DBG(rdata, "Received ADISC request\n");
  1408. adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
  1409. if (!adisc) {
  1410. rjt_data.reason = ELS_RJT_PROT;
  1411. rjt_data.explan = ELS_EXPL_INV_LEN;
  1412. fc_seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
  1413. goto drop;
  1414. }
  1415. fp = fc_frame_alloc(lport, sizeof(*adisc));
  1416. if (!fp)
  1417. goto drop;
  1418. fc_adisc_fill(lport, fp);
  1419. adisc = fc_frame_payload_get(fp, sizeof(*adisc));
  1420. adisc->adisc_cmd = ELS_LS_ACC;
  1421. fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
  1422. lport->tt.frame_send(lport, fp);
  1423. drop:
  1424. fc_frame_free(in_fp);
  1425. }
  1426. /**
  1427. * fc_rport_recv_rls_req() - Handle received Read Link Status request
  1428. * @rdata: The remote port that sent the RLS request
  1429. * @rx_fp: The PRLI request frame
  1430. */
  1431. static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
  1432. struct fc_frame *rx_fp)
  1433. {
  1434. struct fc_lport *lport = rdata->local_port;
  1435. struct fc_frame *fp;
  1436. struct fc_els_rls *rls;
  1437. struct fc_els_rls_resp *rsp;
  1438. struct fc_els_lesb *lesb;
  1439. struct fc_seq_els_data rjt_data;
  1440. struct fc_host_statistics *hst;
  1441. lockdep_assert_held(&rdata->rp_mutex);
  1442. FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
  1443. fc_rport_state(rdata));
  1444. rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
  1445. if (!rls) {
  1446. rjt_data.reason = ELS_RJT_PROT;
  1447. rjt_data.explan = ELS_EXPL_INV_LEN;
  1448. goto out_rjt;
  1449. }
  1450. fp = fc_frame_alloc(lport, sizeof(*rsp));
  1451. if (!fp) {
  1452. rjt_data.reason = ELS_RJT_UNAB;
  1453. rjt_data.explan = ELS_EXPL_INSUF_RES;
  1454. goto out_rjt;
  1455. }
  1456. rsp = fc_frame_payload_get(fp, sizeof(*rsp));
  1457. memset(rsp, 0, sizeof(*rsp));
  1458. rsp->rls_cmd = ELS_LS_ACC;
  1459. lesb = &rsp->rls_lesb;
  1460. if (lport->tt.get_lesb) {
  1461. /* get LESB from LLD if it supports it */
  1462. lport->tt.get_lesb(lport, lesb);
  1463. } else {
  1464. fc_get_host_stats(lport->host);
  1465. hst = &lport->host_stats;
  1466. lesb->lesb_link_fail = htonl(hst->link_failure_count);
  1467. lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
  1468. lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
  1469. lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
  1470. lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
  1471. lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
  1472. }
  1473. fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
  1474. lport->tt.frame_send(lport, fp);
  1475. goto out;
  1476. out_rjt:
  1477. fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
  1478. out:
  1479. fc_frame_free(rx_fp);
  1480. }
  1481. /**
  1482. * fc_rport_recv_els_req() - Handler for validated ELS requests
  1483. * @lport: The local port that received the ELS request
  1484. * @fp: The ELS request frame
  1485. *
  1486. * Handle incoming ELS requests that require port login.
  1487. * The ELS opcode has already been validated by the caller.
  1488. *
  1489. * Reference counting: does not modify kref
  1490. */
  1491. static void fc_rport_recv_els_req(struct fc_lport *lport, struct fc_frame *fp)
  1492. {
  1493. struct fc_rport_priv *rdata;
  1494. struct fc_seq_els_data els_data;
  1495. lockdep_assert_held(&lport->lp_mutex);
  1496. rdata = fc_rport_lookup(lport, fc_frame_sid(fp));
  1497. if (!rdata) {
  1498. FC_RPORT_ID_DBG(lport, fc_frame_sid(fp),
  1499. "Received ELS 0x%02x from non-logged-in port\n",
  1500. fc_frame_payload_op(fp));
  1501. goto reject;
  1502. }
  1503. mutex_lock(&rdata->rp_mutex);
  1504. switch (rdata->rp_state) {
  1505. case RPORT_ST_PRLI:
  1506. case RPORT_ST_RTV:
  1507. case RPORT_ST_READY:
  1508. case RPORT_ST_ADISC:
  1509. break;
  1510. case RPORT_ST_PLOGI:
  1511. if (fc_frame_payload_op(fp) == ELS_PRLI) {
  1512. FC_RPORT_DBG(rdata, "Reject ELS PRLI "
  1513. "while in state %s\n",
  1514. fc_rport_state(rdata));
  1515. mutex_unlock(&rdata->rp_mutex);
  1516. kref_put(&rdata->kref, fc_rport_destroy);
  1517. goto busy;
  1518. }
  1519. fallthrough;
  1520. default:
  1521. FC_RPORT_DBG(rdata,
  1522. "Reject ELS 0x%02x while in state %s\n",
  1523. fc_frame_payload_op(fp), fc_rport_state(rdata));
  1524. mutex_unlock(&rdata->rp_mutex);
  1525. kref_put(&rdata->kref, fc_rport_destroy);
  1526. goto reject;
  1527. }
  1528. switch (fc_frame_payload_op(fp)) {
  1529. case ELS_PRLI:
  1530. fc_rport_recv_prli_req(rdata, fp);
  1531. break;
  1532. case ELS_PRLO:
  1533. fc_rport_recv_prlo_req(rdata, fp);
  1534. break;
  1535. case ELS_ADISC:
  1536. fc_rport_recv_adisc_req(rdata, fp);
  1537. break;
  1538. case ELS_RRQ:
  1539. fc_seq_els_rsp_send(fp, ELS_RRQ, NULL);
  1540. fc_frame_free(fp);
  1541. break;
  1542. case ELS_REC:
  1543. fc_seq_els_rsp_send(fp, ELS_REC, NULL);
  1544. fc_frame_free(fp);
  1545. break;
  1546. case ELS_RLS:
  1547. fc_rport_recv_rls_req(rdata, fp);
  1548. break;
  1549. case ELS_RTV:
  1550. fc_rport_recv_rtv_req(rdata, fp);
  1551. break;
  1552. default:
  1553. fc_frame_free(fp); /* can't happen */
  1554. break;
  1555. }
  1556. mutex_unlock(&rdata->rp_mutex);
  1557. kref_put(&rdata->kref, fc_rport_destroy);
  1558. return;
  1559. reject:
  1560. els_data.reason = ELS_RJT_UNAB;
  1561. els_data.explan = ELS_EXPL_PLOGI_REQD;
  1562. fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
  1563. fc_frame_free(fp);
  1564. return;
  1565. busy:
  1566. els_data.reason = ELS_RJT_BUSY;
  1567. els_data.explan = ELS_EXPL_NONE;
  1568. fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
  1569. fc_frame_free(fp);
  1570. return;
  1571. }
  1572. /**
  1573. * fc_rport_recv_req() - Handler for requests
  1574. * @lport: The local port that received the request
  1575. * @fp: The request frame
  1576. *
  1577. * Reference counting: does not modify kref
  1578. */
  1579. void fc_rport_recv_req(struct fc_lport *lport, struct fc_frame *fp)
  1580. {
  1581. struct fc_seq_els_data els_data;
  1582. lockdep_assert_held(&lport->lp_mutex);
  1583. /*
  1584. * Handle FLOGI, PLOGI and LOGO requests separately, since they
  1585. * don't require prior login.
  1586. * Check for unsupported opcodes first and reject them.
  1587. * For some ops, it would be incorrect to reject with "PLOGI required".
  1588. */
  1589. switch (fc_frame_payload_op(fp)) {
  1590. case ELS_FLOGI:
  1591. fc_rport_recv_flogi_req(lport, fp);
  1592. break;
  1593. case ELS_PLOGI:
  1594. fc_rport_recv_plogi_req(lport, fp);
  1595. break;
  1596. case ELS_LOGO:
  1597. fc_rport_recv_logo_req(lport, fp);
  1598. break;
  1599. case ELS_PRLI:
  1600. case ELS_PRLO:
  1601. case ELS_ADISC:
  1602. case ELS_RRQ:
  1603. case ELS_REC:
  1604. case ELS_RLS:
  1605. case ELS_RTV:
  1606. fc_rport_recv_els_req(lport, fp);
  1607. break;
  1608. default:
  1609. els_data.reason = ELS_RJT_UNSUP;
  1610. els_data.explan = ELS_EXPL_NONE;
  1611. fc_seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
  1612. fc_frame_free(fp);
  1613. break;
  1614. }
  1615. }
  1616. EXPORT_SYMBOL(fc_rport_recv_req);
  1617. /**
  1618. * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
  1619. * @lport: The local port that received the PLOGI request
  1620. * @rx_fp: The PLOGI request frame
  1621. *
  1622. * Reference counting: increments kref on return
  1623. */
  1624. static void fc_rport_recv_plogi_req(struct fc_lport *lport,
  1625. struct fc_frame *rx_fp)
  1626. {
  1627. struct fc_disc *disc;
  1628. struct fc_rport_priv *rdata;
  1629. struct fc_frame *fp = rx_fp;
  1630. struct fc_els_flogi *pl;
  1631. struct fc_seq_els_data rjt_data;
  1632. u32 sid;
  1633. lockdep_assert_held(&lport->lp_mutex);
  1634. sid = fc_frame_sid(fp);
  1635. FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
  1636. pl = fc_frame_payload_get(fp, sizeof(*pl));
  1637. if (!pl) {
  1638. FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
  1639. rjt_data.reason = ELS_RJT_PROT;
  1640. rjt_data.explan = ELS_EXPL_INV_LEN;
  1641. goto reject;
  1642. }
  1643. disc = &lport->disc;
  1644. mutex_lock(&disc->disc_mutex);
  1645. rdata = fc_rport_create(lport, sid);
  1646. if (!rdata) {
  1647. mutex_unlock(&disc->disc_mutex);
  1648. rjt_data.reason = ELS_RJT_UNAB;
  1649. rjt_data.explan = ELS_EXPL_INSUF_RES;
  1650. goto reject;
  1651. }
  1652. mutex_lock(&rdata->rp_mutex);
  1653. mutex_unlock(&disc->disc_mutex);
  1654. rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
  1655. rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
  1656. /*
  1657. * If the rport was just created, possibly due to the incoming PLOGI,
  1658. * set the state appropriately and accept the PLOGI.
  1659. *
  1660. * If we had also sent a PLOGI, and if the received PLOGI is from a
  1661. * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
  1662. * "command already in progress".
  1663. *
  1664. * XXX TBD: If the session was ready before, the PLOGI should result in
  1665. * all outstanding exchanges being reset.
  1666. */
  1667. switch (rdata->rp_state) {
  1668. case RPORT_ST_INIT:
  1669. FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
  1670. break;
  1671. case RPORT_ST_PLOGI_WAIT:
  1672. FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI_WAIT state\n");
  1673. break;
  1674. case RPORT_ST_PLOGI:
  1675. FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
  1676. if (rdata->ids.port_name < lport->wwpn) {
  1677. mutex_unlock(&rdata->rp_mutex);
  1678. rjt_data.reason = ELS_RJT_INPROG;
  1679. rjt_data.explan = ELS_EXPL_NONE;
  1680. goto reject;
  1681. }
  1682. break;
  1683. case RPORT_ST_PRLI:
  1684. case RPORT_ST_RTV:
  1685. case RPORT_ST_READY:
  1686. case RPORT_ST_ADISC:
  1687. FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
  1688. "- ignored for now\n", rdata->rp_state);
  1689. /* XXX TBD - should reset */
  1690. break;
  1691. case RPORT_ST_FLOGI:
  1692. case RPORT_ST_DELETE:
  1693. FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
  1694. fc_rport_state(rdata));
  1695. mutex_unlock(&rdata->rp_mutex);
  1696. rjt_data.reason = ELS_RJT_BUSY;
  1697. rjt_data.explan = ELS_EXPL_NONE;
  1698. goto reject;
  1699. }
  1700. if (!fc_rport_compatible_roles(lport, rdata)) {
  1701. FC_RPORT_DBG(rdata, "Received PLOGI for incompatible role\n");
  1702. mutex_unlock(&rdata->rp_mutex);
  1703. rjt_data.reason = ELS_RJT_LOGIC;
  1704. rjt_data.explan = ELS_EXPL_NONE;
  1705. goto reject;
  1706. }
  1707. /*
  1708. * Get session payload size from incoming PLOGI.
  1709. */
  1710. rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
  1711. /*
  1712. * Send LS_ACC. If this fails, the originator should retry.
  1713. */
  1714. fp = fc_frame_alloc(lport, sizeof(*pl));
  1715. if (!fp)
  1716. goto out;
  1717. fc_plogi_fill(lport, fp, ELS_LS_ACC);
  1718. fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
  1719. lport->tt.frame_send(lport, fp);
  1720. fc_rport_enter_prli(rdata);
  1721. out:
  1722. mutex_unlock(&rdata->rp_mutex);
  1723. fc_frame_free(rx_fp);
  1724. return;
  1725. reject:
  1726. fc_seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
  1727. fc_frame_free(fp);
  1728. }
  1729. /**
  1730. * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
  1731. * @rdata: The remote port that sent the PRLI request
  1732. * @rx_fp: The PRLI request frame
  1733. */
  1734. static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
  1735. struct fc_frame *rx_fp)
  1736. {
  1737. struct fc_lport *lport = rdata->local_port;
  1738. struct fc_frame *fp;
  1739. struct {
  1740. struct fc_els_prli prli;
  1741. struct fc_els_spp spp;
  1742. } *pp;
  1743. struct fc_els_spp *rspp; /* request service param page */
  1744. struct fc_els_spp *spp; /* response spp */
  1745. unsigned int len;
  1746. unsigned int plen;
  1747. enum fc_els_spp_resp resp;
  1748. struct fc_seq_els_data rjt_data;
  1749. struct fc4_prov *prov;
  1750. lockdep_assert_held(&rdata->rp_mutex);
  1751. FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
  1752. fc_rport_state(rdata));
  1753. len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
  1754. pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
  1755. if (!pp)
  1756. goto reject_len;
  1757. plen = ntohs(pp->prli.prli_len);
  1758. if ((plen % 4) != 0 || plen > len || plen < 16)
  1759. goto reject_len;
  1760. if (plen < len)
  1761. len = plen;
  1762. plen = pp->prli.prli_spp_len;
  1763. if ((plen % 4) != 0 || plen < sizeof(*spp) ||
  1764. plen > len || len < sizeof(*pp) || plen < 12)
  1765. goto reject_len;
  1766. rspp = &pp->spp;
  1767. fp = fc_frame_alloc(lport, len);
  1768. if (!fp) {
  1769. rjt_data.reason = ELS_RJT_UNAB;
  1770. rjt_data.explan = ELS_EXPL_INSUF_RES;
  1771. goto reject;
  1772. }
  1773. pp = fc_frame_payload_get(fp, len);
  1774. WARN_ON(!pp);
  1775. memset(pp, 0, len);
  1776. pp->prli.prli_cmd = ELS_LS_ACC;
  1777. pp->prli.prli_spp_len = plen;
  1778. pp->prli.prli_len = htons(len);
  1779. len -= sizeof(struct fc_els_prli);
  1780. /*
  1781. * Go through all the service parameter pages and build
  1782. * response. If plen indicates longer SPP than standard,
  1783. * use that. The entire response has been pre-cleared above.
  1784. */
  1785. spp = &pp->spp;
  1786. mutex_lock(&fc_prov_mutex);
  1787. while (len >= plen) {
  1788. rdata->spp_type = rspp->spp_type;
  1789. spp->spp_type = rspp->spp_type;
  1790. spp->spp_type_ext = rspp->spp_type_ext;
  1791. resp = 0;
  1792. if (rspp->spp_type < FC_FC4_PROV_SIZE) {
  1793. enum fc_els_spp_resp active = 0, passive = 0;
  1794. prov = fc_active_prov[rspp->spp_type];
  1795. if (prov)
  1796. active = prov->prli(rdata, plen, rspp, spp);
  1797. prov = fc_passive_prov[rspp->spp_type];
  1798. if (prov)
  1799. passive = prov->prli(rdata, plen, rspp, spp);
  1800. if (!active || passive == FC_SPP_RESP_ACK)
  1801. resp = passive;
  1802. else
  1803. resp = active;
  1804. FC_RPORT_DBG(rdata, "PRLI rspp type %x "
  1805. "active %x passive %x\n",
  1806. rspp->spp_type, active, passive);
  1807. }
  1808. if (!resp) {
  1809. if (spp->spp_flags & FC_SPP_EST_IMG_PAIR)
  1810. resp |= FC_SPP_RESP_CONF;
  1811. else
  1812. resp |= FC_SPP_RESP_INVL;
  1813. }
  1814. spp->spp_flags |= resp;
  1815. len -= plen;
  1816. rspp = (struct fc_els_spp *)((char *)rspp + plen);
  1817. spp = (struct fc_els_spp *)((char *)spp + plen);
  1818. }
  1819. mutex_unlock(&fc_prov_mutex);
  1820. /*
  1821. * Send LS_ACC. If this fails, the originator should retry.
  1822. */
  1823. fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
  1824. lport->tt.frame_send(lport, fp);
  1825. goto drop;
  1826. reject_len:
  1827. rjt_data.reason = ELS_RJT_PROT;
  1828. rjt_data.explan = ELS_EXPL_INV_LEN;
  1829. reject:
  1830. fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
  1831. drop:
  1832. fc_frame_free(rx_fp);
  1833. }
  1834. /**
  1835. * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
  1836. * @rdata: The remote port that sent the PRLO request
  1837. * @rx_fp: The PRLO request frame
  1838. */
  1839. static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
  1840. struct fc_frame *rx_fp)
  1841. {
  1842. struct fc_lport *lport = rdata->local_port;
  1843. struct fc_frame *fp;
  1844. struct {
  1845. struct fc_els_prlo prlo;
  1846. struct fc_els_spp spp;
  1847. } *pp;
  1848. struct fc_els_spp *rspp; /* request service param page */
  1849. struct fc_els_spp *spp; /* response spp */
  1850. unsigned int len;
  1851. unsigned int plen;
  1852. struct fc_seq_els_data rjt_data;
  1853. lockdep_assert_held(&rdata->rp_mutex);
  1854. FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
  1855. fc_rport_state(rdata));
  1856. len = fr_len(rx_fp) - sizeof(struct fc_frame_header);
  1857. pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
  1858. if (!pp)
  1859. goto reject_len;
  1860. plen = ntohs(pp->prlo.prlo_len);
  1861. if (plen != 20)
  1862. goto reject_len;
  1863. if (plen < len)
  1864. len = plen;
  1865. rspp = &pp->spp;
  1866. fp = fc_frame_alloc(lport, len);
  1867. if (!fp) {
  1868. rjt_data.reason = ELS_RJT_UNAB;
  1869. rjt_data.explan = ELS_EXPL_INSUF_RES;
  1870. goto reject;
  1871. }
  1872. pp = fc_frame_payload_get(fp, len);
  1873. WARN_ON(!pp);
  1874. memset(pp, 0, len);
  1875. pp->prlo.prlo_cmd = ELS_LS_ACC;
  1876. pp->prlo.prlo_obs = 0x10;
  1877. pp->prlo.prlo_len = htons(len);
  1878. spp = &pp->spp;
  1879. spp->spp_type = rspp->spp_type;
  1880. spp->spp_type_ext = rspp->spp_type_ext;
  1881. spp->spp_flags = FC_SPP_RESP_ACK;
  1882. fc_rport_enter_prli(rdata);
  1883. fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_ELS_REP, 0);
  1884. lport->tt.frame_send(lport, fp);
  1885. goto drop;
  1886. reject_len:
  1887. rjt_data.reason = ELS_RJT_PROT;
  1888. rjt_data.explan = ELS_EXPL_INV_LEN;
  1889. reject:
  1890. fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data);
  1891. drop:
  1892. fc_frame_free(rx_fp);
  1893. }
  1894. /**
  1895. * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
  1896. * @lport: The local port that received the LOGO request
  1897. * @fp: The LOGO request frame
  1898. *
  1899. * Reference counting: drops kref on return
  1900. */
  1901. static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
  1902. {
  1903. struct fc_rport_priv *rdata;
  1904. u32 sid;
  1905. lockdep_assert_held(&lport->lp_mutex);
  1906. fc_seq_els_rsp_send(fp, ELS_LS_ACC, NULL);
  1907. sid = fc_frame_sid(fp);
  1908. rdata = fc_rport_lookup(lport, sid);
  1909. if (rdata) {
  1910. mutex_lock(&rdata->rp_mutex);
  1911. FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
  1912. fc_rport_state(rdata));
  1913. fc_rport_enter_delete(rdata, RPORT_EV_STOP);
  1914. mutex_unlock(&rdata->rp_mutex);
  1915. kref_put(&rdata->kref, fc_rport_destroy);
  1916. } else
  1917. FC_RPORT_ID_DBG(lport, sid,
  1918. "Received LOGO from non-logged-in port\n");
  1919. fc_frame_free(fp);
  1920. }
  1921. /**
  1922. * fc_rport_flush_queue() - Flush the rport_event_queue
  1923. */
  1924. void fc_rport_flush_queue(void)
  1925. {
  1926. flush_workqueue(rport_event_queue);
  1927. }
  1928. EXPORT_SYMBOL(fc_rport_flush_queue);
  1929. /**
  1930. * fc_rport_fcp_prli() - Handle incoming PRLI for the FCP initiator.
  1931. * @rdata: remote port private
  1932. * @spp_len: service parameter page length
  1933. * @rspp: received service parameter page
  1934. * @spp: response service parameter page
  1935. *
  1936. * Returns the value for the response code to be placed in spp_flags;
  1937. * Returns 0 if not an initiator.
  1938. */
  1939. static int fc_rport_fcp_prli(struct fc_rport_priv *rdata, u32 spp_len,
  1940. const struct fc_els_spp *rspp,
  1941. struct fc_els_spp *spp)
  1942. {
  1943. struct fc_lport *lport = rdata->local_port;
  1944. u32 fcp_parm;
  1945. fcp_parm = ntohl(rspp->spp_params);
  1946. rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
  1947. if (fcp_parm & FCP_SPPF_INIT_FCN)
  1948. rdata->ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  1949. if (fcp_parm & FCP_SPPF_TARG_FCN)
  1950. rdata->ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  1951. if (fcp_parm & FCP_SPPF_RETRY)
  1952. rdata->flags |= FC_RP_FLAGS_RETRY;
  1953. rdata->supported_classes = FC_COS_CLASS3;
  1954. if (!(lport->service_params & FCP_SPPF_INIT_FCN))
  1955. return 0;
  1956. spp->spp_flags |= rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
  1957. /*
  1958. * OR in our service parameters with other providers (target), if any.
  1959. */
  1960. fcp_parm = ntohl(spp->spp_params);
  1961. spp->spp_params = htonl(fcp_parm | lport->service_params);
  1962. return FC_SPP_RESP_ACK;
  1963. }
  1964. /*
  1965. * FC-4 provider ops for FCP initiator.
  1966. */
  1967. struct fc4_prov fc_rport_fcp_init = {
  1968. .prli = fc_rport_fcp_prli,
  1969. };
  1970. /**
  1971. * fc_rport_t0_prli() - Handle incoming PRLI parameters for type 0
  1972. * @rdata: remote port private
  1973. * @spp_len: service parameter page length
  1974. * @rspp: received service parameter page
  1975. * @spp: response service parameter page
  1976. */
  1977. static int fc_rport_t0_prli(struct fc_rport_priv *rdata, u32 spp_len,
  1978. const struct fc_els_spp *rspp,
  1979. struct fc_els_spp *spp)
  1980. {
  1981. if (rspp->spp_flags & FC_SPP_EST_IMG_PAIR)
  1982. return FC_SPP_RESP_INVL;
  1983. return FC_SPP_RESP_ACK;
  1984. }
  1985. /*
  1986. * FC-4 provider ops for type 0 service parameters.
  1987. *
  1988. * This handles the special case of type 0 which is always successful
  1989. * but doesn't do anything otherwise.
  1990. */
  1991. struct fc4_prov fc_rport_t0_prov = {
  1992. .prli = fc_rport_t0_prli,
  1993. };
  1994. /**
  1995. * fc_setup_rport() - Initialize the rport_event_queue
  1996. */
  1997. int fc_setup_rport(void)
  1998. {
  1999. rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
  2000. if (!rport_event_queue)
  2001. return -ENOMEM;
  2002. return 0;
  2003. }
  2004. /**
  2005. * fc_destroy_rport() - Destroy the rport_event_queue
  2006. */
  2007. void fc_destroy_rport(void)
  2008. {
  2009. destroy_workqueue(rport_event_queue);
  2010. }
  2011. /**
  2012. * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
  2013. * @rport: The remote port whose I/O should be terminated
  2014. */
  2015. void fc_rport_terminate_io(struct fc_rport *rport)
  2016. {
  2017. struct fc_rport_libfc_priv *rpriv = rport->dd_data;
  2018. struct fc_lport *lport = rpriv->local_port;
  2019. lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
  2020. lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
  2021. }
  2022. EXPORT_SYMBOL(fc_rport_terminate_io);