fc_rport.c 60 KB

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