fc_rport.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  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 heirarchy.
  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. #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 <asm/unaligned.h>
  52. #include <scsi/libfc.h>
  53. #include <scsi/fc_encode.h>
  54. #include "fc_libfc.h"
  55. struct workqueue_struct *rport_event_queue;
  56. static void fc_rport_enter_plogi(struct fc_rport_priv *);
  57. static void fc_rport_enter_prli(struct fc_rport_priv *);
  58. static void fc_rport_enter_rtv(struct fc_rport_priv *);
  59. static void fc_rport_enter_ready(struct fc_rport_priv *);
  60. static void fc_rport_enter_logo(struct fc_rport_priv *);
  61. static void fc_rport_enter_adisc(struct fc_rport_priv *);
  62. static void fc_rport_recv_plogi_req(struct fc_lport *,
  63. struct fc_seq *, struct fc_frame *);
  64. static void fc_rport_recv_prli_req(struct fc_rport_priv *,
  65. struct fc_seq *, struct fc_frame *);
  66. static void fc_rport_recv_prlo_req(struct fc_rport_priv *,
  67. struct fc_seq *, struct fc_frame *);
  68. static void fc_rport_recv_logo_req(struct fc_lport *,
  69. struct fc_seq *, struct fc_frame *);
  70. static void fc_rport_timeout(struct work_struct *);
  71. static void fc_rport_error(struct fc_rport_priv *, struct fc_frame *);
  72. static void fc_rport_error_retry(struct fc_rport_priv *, struct fc_frame *);
  73. static void fc_rport_work(struct work_struct *);
  74. static const char *fc_rport_state_names[] = {
  75. [RPORT_ST_INIT] = "Init",
  76. [RPORT_ST_PLOGI] = "PLOGI",
  77. [RPORT_ST_PRLI] = "PRLI",
  78. [RPORT_ST_RTV] = "RTV",
  79. [RPORT_ST_READY] = "Ready",
  80. [RPORT_ST_LOGO] = "LOGO",
  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. static struct fc_rport_priv *fc_rport_lookup(const struct fc_lport *lport,
  90. u32 port_id)
  91. {
  92. struct fc_rport_priv *rdata;
  93. list_for_each_entry(rdata, &lport->disc.rports, peers)
  94. if (rdata->ids.port_id == port_id)
  95. return rdata;
  96. return NULL;
  97. }
  98. /**
  99. * fc_rport_create() - Create a new remote port
  100. * @lport: The local port this remote port will be associated with
  101. * @ids: The identifiers for the new remote port
  102. *
  103. * The remote port will start in the INIT state.
  104. *
  105. * Locking note: must be called with the disc_mutex held.
  106. */
  107. static struct fc_rport_priv *fc_rport_create(struct fc_lport *lport,
  108. u32 port_id)
  109. {
  110. struct fc_rport_priv *rdata;
  111. rdata = lport->tt.rport_lookup(lport, port_id);
  112. if (rdata)
  113. return rdata;
  114. rdata = kzalloc(sizeof(*rdata), GFP_KERNEL);
  115. if (!rdata)
  116. return NULL;
  117. rdata->ids.node_name = -1;
  118. rdata->ids.port_name = -1;
  119. rdata->ids.port_id = port_id;
  120. rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
  121. kref_init(&rdata->kref);
  122. mutex_init(&rdata->rp_mutex);
  123. rdata->local_port = lport;
  124. rdata->rp_state = RPORT_ST_INIT;
  125. rdata->event = RPORT_EV_NONE;
  126. rdata->flags = FC_RP_FLAGS_REC_SUPPORTED;
  127. rdata->e_d_tov = lport->e_d_tov;
  128. rdata->r_a_tov = lport->r_a_tov;
  129. rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
  130. INIT_DELAYED_WORK(&rdata->retry_work, fc_rport_timeout);
  131. INIT_WORK(&rdata->event_work, fc_rport_work);
  132. if (port_id != FC_FID_DIR_SERV)
  133. list_add(&rdata->peers, &lport->disc.rports);
  134. return rdata;
  135. }
  136. /**
  137. * fc_rport_destroy() - Free a remote port after last reference is released
  138. * @kref: The remote port's kref
  139. */
  140. static void fc_rport_destroy(struct kref *kref)
  141. {
  142. struct fc_rport_priv *rdata;
  143. rdata = container_of(kref, struct fc_rport_priv, kref);
  144. kfree(rdata);
  145. }
  146. /**
  147. * fc_rport_state() - Return a string identifying the remote port's state
  148. * @rdata: The remote port
  149. */
  150. static const char *fc_rport_state(struct fc_rport_priv *rdata)
  151. {
  152. const char *cp;
  153. cp = fc_rport_state_names[rdata->rp_state];
  154. if (!cp)
  155. cp = "Unknown";
  156. return cp;
  157. }
  158. /**
  159. * fc_set_rport_loss_tmo() - Set the remote port loss timeout
  160. * @rport: The remote port that gets a new timeout value
  161. * @timeout: The new timeout value (in seconds)
  162. */
  163. void fc_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
  164. {
  165. if (timeout)
  166. rport->dev_loss_tmo = timeout + 5;
  167. else
  168. rport->dev_loss_tmo = 30;
  169. }
  170. EXPORT_SYMBOL(fc_set_rport_loss_tmo);
  171. /**
  172. * fc_plogi_get_maxframe() - Get the maximum payload from the common service
  173. * parameters in a FLOGI frame
  174. * @flp: The FLOGI payload
  175. * @maxval: The maximum frame size upper limit; this may be less than what
  176. * is in the service parameters
  177. */
  178. static unsigned int fc_plogi_get_maxframe(struct fc_els_flogi *flp,
  179. unsigned int maxval)
  180. {
  181. unsigned int mfs;
  182. /*
  183. * Get max payload from the common service parameters and the
  184. * class 3 receive data field size.
  185. */
  186. mfs = ntohs(flp->fl_csp.sp_bb_data) & FC_SP_BB_DATA_MASK;
  187. if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
  188. maxval = mfs;
  189. mfs = ntohs(flp->fl_cssp[3 - 1].cp_rdfs);
  190. if (mfs >= FC_SP_MIN_MAX_PAYLOAD && mfs < maxval)
  191. maxval = mfs;
  192. return maxval;
  193. }
  194. /**
  195. * fc_rport_state_enter() - Change the state of a remote port
  196. * @rdata: The remote port whose state should change
  197. * @new: The new state
  198. *
  199. * Locking Note: Called with the rport lock held
  200. */
  201. static void fc_rport_state_enter(struct fc_rport_priv *rdata,
  202. enum fc_rport_state new)
  203. {
  204. if (rdata->rp_state != new)
  205. rdata->retries = 0;
  206. rdata->rp_state = new;
  207. }
  208. /**
  209. * fc_rport_work() - Handler for remote port events in the rport_event_queue
  210. * @work: Handle to the remote port being dequeued
  211. */
  212. static void fc_rport_work(struct work_struct *work)
  213. {
  214. u32 port_id;
  215. struct fc_rport_priv *rdata =
  216. container_of(work, struct fc_rport_priv, event_work);
  217. struct fc_rport_libfc_priv *rpriv;
  218. enum fc_rport_event event;
  219. struct fc_lport *lport = rdata->local_port;
  220. struct fc_rport_operations *rport_ops;
  221. struct fc_rport_identifiers ids;
  222. struct fc_rport *rport;
  223. mutex_lock(&rdata->rp_mutex);
  224. event = rdata->event;
  225. rport_ops = rdata->ops;
  226. rport = rdata->rport;
  227. FC_RPORT_DBG(rdata, "work event %u\n", event);
  228. switch (event) {
  229. case RPORT_EV_READY:
  230. ids = rdata->ids;
  231. rdata->event = RPORT_EV_NONE;
  232. kref_get(&rdata->kref);
  233. mutex_unlock(&rdata->rp_mutex);
  234. if (!rport)
  235. rport = fc_remote_port_add(lport->host, 0, &ids);
  236. if (!rport) {
  237. FC_RPORT_DBG(rdata, "Failed to add the rport\n");
  238. lport->tt.rport_logoff(rdata);
  239. kref_put(&rdata->kref, lport->tt.rport_destroy);
  240. return;
  241. }
  242. mutex_lock(&rdata->rp_mutex);
  243. if (rdata->rport)
  244. FC_RPORT_DBG(rdata, "rport already allocated\n");
  245. rdata->rport = rport;
  246. rport->maxframe_size = rdata->maxframe_size;
  247. rport->supported_classes = rdata->supported_classes;
  248. rpriv = rport->dd_data;
  249. rpriv->local_port = lport;
  250. rpriv->rp_state = rdata->rp_state;
  251. rpriv->flags = rdata->flags;
  252. rpriv->e_d_tov = rdata->e_d_tov;
  253. rpriv->r_a_tov = rdata->r_a_tov;
  254. mutex_unlock(&rdata->rp_mutex);
  255. if (rport_ops && rport_ops->event_callback) {
  256. FC_RPORT_DBG(rdata, "callback ev %d\n", event);
  257. rport_ops->event_callback(lport, rdata, event);
  258. }
  259. kref_put(&rdata->kref, lport->tt.rport_destroy);
  260. break;
  261. case RPORT_EV_FAILED:
  262. case RPORT_EV_LOGO:
  263. case RPORT_EV_STOP:
  264. port_id = rdata->ids.port_id;
  265. mutex_unlock(&rdata->rp_mutex);
  266. if (rport_ops && rport_ops->event_callback) {
  267. FC_RPORT_DBG(rdata, "callback ev %d\n", event);
  268. rport_ops->event_callback(lport, rdata, event);
  269. }
  270. cancel_delayed_work_sync(&rdata->retry_work);
  271. /*
  272. * Reset any outstanding exchanges before freeing rport.
  273. */
  274. lport->tt.exch_mgr_reset(lport, 0, port_id);
  275. lport->tt.exch_mgr_reset(lport, port_id, 0);
  276. if (rport) {
  277. rpriv = rport->dd_data;
  278. rpriv->rp_state = RPORT_ST_DELETE;
  279. mutex_lock(&rdata->rp_mutex);
  280. rdata->rport = NULL;
  281. mutex_unlock(&rdata->rp_mutex);
  282. fc_remote_port_delete(rport);
  283. }
  284. mutex_lock(&lport->disc.disc_mutex);
  285. mutex_lock(&rdata->rp_mutex);
  286. if (rdata->rp_state == RPORT_ST_DELETE) {
  287. if (port_id == FC_FID_DIR_SERV) {
  288. rdata->event = RPORT_EV_NONE;
  289. mutex_unlock(&rdata->rp_mutex);
  290. } else if (rdata->flags & FC_RP_STARTED) {
  291. rdata->event = RPORT_EV_NONE;
  292. FC_RPORT_DBG(rdata, "work restart\n");
  293. fc_rport_enter_plogi(rdata);
  294. mutex_unlock(&rdata->rp_mutex);
  295. } else {
  296. FC_RPORT_DBG(rdata, "work delete\n");
  297. list_del(&rdata->peers);
  298. mutex_unlock(&rdata->rp_mutex);
  299. kref_put(&rdata->kref, lport->tt.rport_destroy);
  300. }
  301. } else {
  302. /*
  303. * Re-open for events. Reissue READY event if ready.
  304. */
  305. rdata->event = RPORT_EV_NONE;
  306. if (rdata->rp_state == RPORT_ST_READY)
  307. fc_rport_enter_ready(rdata);
  308. mutex_unlock(&rdata->rp_mutex);
  309. }
  310. mutex_unlock(&lport->disc.disc_mutex);
  311. break;
  312. default:
  313. mutex_unlock(&rdata->rp_mutex);
  314. break;
  315. }
  316. }
  317. /**
  318. * fc_rport_login() - Start the remote port login state machine
  319. * @rdata: The remote port to be logged in to
  320. *
  321. * Locking Note: Called without the rport lock held. This
  322. * function will hold the rport lock, call an _enter_*
  323. * function and then unlock the rport.
  324. *
  325. * This indicates the intent to be logged into the remote port.
  326. * If it appears we are already logged in, ADISC is used to verify
  327. * the setup.
  328. */
  329. int fc_rport_login(struct fc_rport_priv *rdata)
  330. {
  331. mutex_lock(&rdata->rp_mutex);
  332. rdata->flags |= FC_RP_STARTED;
  333. switch (rdata->rp_state) {
  334. case RPORT_ST_READY:
  335. FC_RPORT_DBG(rdata, "ADISC port\n");
  336. fc_rport_enter_adisc(rdata);
  337. break;
  338. case RPORT_ST_DELETE:
  339. FC_RPORT_DBG(rdata, "Restart deleted port\n");
  340. break;
  341. default:
  342. FC_RPORT_DBG(rdata, "Login to port\n");
  343. fc_rport_enter_plogi(rdata);
  344. break;
  345. }
  346. mutex_unlock(&rdata->rp_mutex);
  347. return 0;
  348. }
  349. /**
  350. * fc_rport_enter_delete() - Schedule a remote port to be deleted
  351. * @rdata: The remote port to be deleted
  352. * @event: The event to report as the reason for deletion
  353. *
  354. * Locking Note: Called with the rport lock held.
  355. *
  356. * Allow state change into DELETE only once.
  357. *
  358. * Call queue_work only if there's no event already pending.
  359. * Set the new event so that the old pending event will not occur.
  360. * Since we have the mutex, even if fc_rport_work() is already started,
  361. * it'll see the new event.
  362. */
  363. static void fc_rport_enter_delete(struct fc_rport_priv *rdata,
  364. enum fc_rport_event event)
  365. {
  366. if (rdata->rp_state == RPORT_ST_DELETE)
  367. return;
  368. FC_RPORT_DBG(rdata, "Delete port\n");
  369. fc_rport_state_enter(rdata, RPORT_ST_DELETE);
  370. if (rdata->event == RPORT_EV_NONE)
  371. queue_work(rport_event_queue, &rdata->event_work);
  372. rdata->event = event;
  373. }
  374. /**
  375. * fc_rport_logoff() - Logoff and remove a remote port
  376. * @rdata: The remote port to be logged off of
  377. *
  378. * Locking Note: Called without the rport lock held. This
  379. * function will hold the rport lock, call an _enter_*
  380. * function and then unlock the rport.
  381. */
  382. int fc_rport_logoff(struct fc_rport_priv *rdata)
  383. {
  384. mutex_lock(&rdata->rp_mutex);
  385. FC_RPORT_DBG(rdata, "Remove port\n");
  386. rdata->flags &= ~FC_RP_STARTED;
  387. if (rdata->rp_state == RPORT_ST_DELETE) {
  388. FC_RPORT_DBG(rdata, "Port in Delete state, not removing\n");
  389. goto out;
  390. }
  391. fc_rport_enter_logo(rdata);
  392. /*
  393. * Change the state to Delete so that we discard
  394. * the response.
  395. */
  396. fc_rport_enter_delete(rdata, RPORT_EV_STOP);
  397. out:
  398. mutex_unlock(&rdata->rp_mutex);
  399. return 0;
  400. }
  401. /**
  402. * fc_rport_enter_ready() - Transition to the RPORT_ST_READY state
  403. * @rdata: The remote port that is ready
  404. *
  405. * Locking Note: The rport lock is expected to be held before calling
  406. * this routine.
  407. */
  408. static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
  409. {
  410. fc_rport_state_enter(rdata, RPORT_ST_READY);
  411. FC_RPORT_DBG(rdata, "Port is Ready\n");
  412. if (rdata->event == RPORT_EV_NONE)
  413. queue_work(rport_event_queue, &rdata->event_work);
  414. rdata->event = RPORT_EV_READY;
  415. }
  416. /**
  417. * fc_rport_timeout() - Handler for the retry_work timer
  418. * @work: Handle to the remote port that has timed out
  419. *
  420. * Locking Note: Called without the rport lock held. This
  421. * function will hold the rport lock, call an _enter_*
  422. * function and then unlock the rport.
  423. */
  424. static void fc_rport_timeout(struct work_struct *work)
  425. {
  426. struct fc_rport_priv *rdata =
  427. container_of(work, struct fc_rport_priv, retry_work.work);
  428. mutex_lock(&rdata->rp_mutex);
  429. switch (rdata->rp_state) {
  430. case RPORT_ST_PLOGI:
  431. fc_rport_enter_plogi(rdata);
  432. break;
  433. case RPORT_ST_PRLI:
  434. fc_rport_enter_prli(rdata);
  435. break;
  436. case RPORT_ST_RTV:
  437. fc_rport_enter_rtv(rdata);
  438. break;
  439. case RPORT_ST_LOGO:
  440. fc_rport_enter_logo(rdata);
  441. break;
  442. case RPORT_ST_ADISC:
  443. fc_rport_enter_adisc(rdata);
  444. break;
  445. case RPORT_ST_READY:
  446. case RPORT_ST_INIT:
  447. case RPORT_ST_DELETE:
  448. break;
  449. }
  450. mutex_unlock(&rdata->rp_mutex);
  451. }
  452. /**
  453. * fc_rport_error() - Error handler, called once retries have been exhausted
  454. * @rdata: The remote port the error is happened on
  455. * @fp: The error code encapsulated in a frame pointer
  456. *
  457. * Locking Note: The rport lock is expected to be held before
  458. * calling this routine
  459. */
  460. static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp)
  461. {
  462. FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n",
  463. IS_ERR(fp) ? -PTR_ERR(fp) : 0,
  464. fc_rport_state(rdata), rdata->retries);
  465. switch (rdata->rp_state) {
  466. case RPORT_ST_PLOGI:
  467. case RPORT_ST_LOGO:
  468. rdata->flags &= ~FC_RP_STARTED;
  469. fc_rport_enter_delete(rdata, RPORT_EV_FAILED);
  470. break;
  471. case RPORT_ST_RTV:
  472. fc_rport_enter_ready(rdata);
  473. break;
  474. case RPORT_ST_PRLI:
  475. case RPORT_ST_ADISC:
  476. fc_rport_enter_logo(rdata);
  477. break;
  478. case RPORT_ST_DELETE:
  479. case RPORT_ST_READY:
  480. case RPORT_ST_INIT:
  481. break;
  482. }
  483. }
  484. /**
  485. * fc_rport_error_retry() - Handler for remote port state retries
  486. * @rdata: The remote port whose state is to be retried
  487. * @fp: The error code encapsulated in a frame pointer
  488. *
  489. * If the error was an exchange timeout retry immediately,
  490. * otherwise wait for E_D_TOV.
  491. *
  492. * Locking Note: The rport lock is expected to be held before
  493. * calling this routine
  494. */
  495. static void fc_rport_error_retry(struct fc_rport_priv *rdata,
  496. struct fc_frame *fp)
  497. {
  498. unsigned long delay = FC_DEF_E_D_TOV;
  499. /* make sure this isn't an FC_EX_CLOSED error, never retry those */
  500. if (PTR_ERR(fp) == -FC_EX_CLOSED)
  501. return fc_rport_error(rdata, fp);
  502. if (rdata->retries < rdata->local_port->max_rport_retry_count) {
  503. FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n",
  504. PTR_ERR(fp), fc_rport_state(rdata));
  505. rdata->retries++;
  506. /* no additional delay on exchange timeouts */
  507. if (PTR_ERR(fp) == -FC_EX_TIMEOUT)
  508. delay = 0;
  509. schedule_delayed_work(&rdata->retry_work, delay);
  510. return;
  511. }
  512. return fc_rport_error(rdata, fp);
  513. }
  514. /**
  515. * fc_rport_plogi_recv_resp() - Handler for ELS PLOGI responses
  516. * @sp: The sequence the PLOGI is on
  517. * @fp: The PLOGI response frame
  518. * @rdata_arg: The remote port that sent the PLOGI response
  519. *
  520. * Locking Note: This function will be called without the rport lock
  521. * held, but it will lock, call an _enter_* function or fc_rport_error
  522. * and then unlock the rport.
  523. */
  524. static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
  525. void *rdata_arg)
  526. {
  527. struct fc_rport_priv *rdata = rdata_arg;
  528. struct fc_lport *lport = rdata->local_port;
  529. struct fc_els_flogi *plp = NULL;
  530. unsigned int tov;
  531. u16 csp_seq;
  532. u16 cssp_seq;
  533. u8 op;
  534. mutex_lock(&rdata->rp_mutex);
  535. FC_RPORT_DBG(rdata, "Received a PLOGI %s\n", fc_els_resp_type(fp));
  536. if (rdata->rp_state != RPORT_ST_PLOGI) {
  537. FC_RPORT_DBG(rdata, "Received a PLOGI response, but in state "
  538. "%s\n", fc_rport_state(rdata));
  539. if (IS_ERR(fp))
  540. goto err;
  541. goto out;
  542. }
  543. if (IS_ERR(fp)) {
  544. fc_rport_error_retry(rdata, fp);
  545. goto err;
  546. }
  547. op = fc_frame_payload_op(fp);
  548. if (op == ELS_LS_ACC &&
  549. (plp = fc_frame_payload_get(fp, sizeof(*plp))) != NULL) {
  550. rdata->ids.port_name = get_unaligned_be64(&plp->fl_wwpn);
  551. rdata->ids.node_name = get_unaligned_be64(&plp->fl_wwnn);
  552. tov = ntohl(plp->fl_csp.sp_e_d_tov);
  553. if (ntohs(plp->fl_csp.sp_features) & FC_SP_FT_EDTR)
  554. tov /= 1000000;
  555. if (tov > rdata->e_d_tov)
  556. rdata->e_d_tov = tov;
  557. csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
  558. cssp_seq = ntohs(plp->fl_cssp[3 - 1].cp_con_seq);
  559. if (cssp_seq < csp_seq)
  560. csp_seq = cssp_seq;
  561. rdata->max_seq = csp_seq;
  562. rdata->maxframe_size = fc_plogi_get_maxframe(plp, lport->mfs);
  563. fc_rport_enter_prli(rdata);
  564. } else
  565. fc_rport_error_retry(rdata, fp);
  566. out:
  567. fc_frame_free(fp);
  568. err:
  569. mutex_unlock(&rdata->rp_mutex);
  570. kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
  571. }
  572. /**
  573. * fc_rport_enter_plogi() - Send Port Login (PLOGI) request
  574. * @rdata: The remote port to send a PLOGI to
  575. *
  576. * Locking Note: The rport lock is expected to be held before calling
  577. * this routine.
  578. */
  579. static void fc_rport_enter_plogi(struct fc_rport_priv *rdata)
  580. {
  581. struct fc_lport *lport = rdata->local_port;
  582. struct fc_frame *fp;
  583. FC_RPORT_DBG(rdata, "Port entered PLOGI state from %s state\n",
  584. fc_rport_state(rdata));
  585. fc_rport_state_enter(rdata, RPORT_ST_PLOGI);
  586. rdata->maxframe_size = FC_MIN_MAX_PAYLOAD;
  587. fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi));
  588. if (!fp) {
  589. fc_rport_error_retry(rdata, fp);
  590. return;
  591. }
  592. rdata->e_d_tov = lport->e_d_tov;
  593. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PLOGI,
  594. fc_rport_plogi_resp, rdata,
  595. 2 * lport->r_a_tov))
  596. fc_rport_error_retry(rdata, NULL);
  597. else
  598. kref_get(&rdata->kref);
  599. }
  600. /**
  601. * fc_rport_prli_resp() - Process Login (PRLI) response handler
  602. * @sp: The sequence the PRLI response was on
  603. * @fp: The PRLI response frame
  604. * @rdata_arg: The remote port that sent the PRLI response
  605. *
  606. * Locking Note: This function will be called without the rport lock
  607. * held, but it will lock, call an _enter_* function or fc_rport_error
  608. * and then unlock the rport.
  609. */
  610. static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
  611. void *rdata_arg)
  612. {
  613. struct fc_rport_priv *rdata = rdata_arg;
  614. struct {
  615. struct fc_els_prli prli;
  616. struct fc_els_spp spp;
  617. } *pp;
  618. u32 roles = FC_RPORT_ROLE_UNKNOWN;
  619. u32 fcp_parm = 0;
  620. u8 op;
  621. u8 resp_code = 0;
  622. mutex_lock(&rdata->rp_mutex);
  623. FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
  624. if (rdata->rp_state != RPORT_ST_PRLI) {
  625. FC_RPORT_DBG(rdata, "Received a PRLI response, but in state "
  626. "%s\n", fc_rport_state(rdata));
  627. if (IS_ERR(fp))
  628. goto err;
  629. goto out;
  630. }
  631. if (IS_ERR(fp)) {
  632. fc_rport_error_retry(rdata, fp);
  633. goto err;
  634. }
  635. /* reinitialize remote port roles */
  636. rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
  637. op = fc_frame_payload_op(fp);
  638. if (op == ELS_LS_ACC) {
  639. pp = fc_frame_payload_get(fp, sizeof(*pp));
  640. if (!pp)
  641. goto out;
  642. resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
  643. FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x\n",
  644. pp->spp.spp_flags);
  645. if (resp_code != FC_SPP_RESP_ACK) {
  646. if (resp_code == FC_SPP_RESP_CONF)
  647. fc_rport_error(rdata, fp);
  648. else
  649. fc_rport_error_retry(rdata, fp);
  650. goto out;
  651. }
  652. if (pp->prli.prli_spp_len < sizeof(pp->spp))
  653. goto out;
  654. fcp_parm = ntohl(pp->spp.spp_params);
  655. if (fcp_parm & FCP_SPPF_RETRY)
  656. rdata->flags |= FC_RP_FLAGS_RETRY;
  657. rdata->supported_classes = FC_COS_CLASS3;
  658. if (fcp_parm & FCP_SPPF_INIT_FCN)
  659. roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  660. if (fcp_parm & FCP_SPPF_TARG_FCN)
  661. roles |= FC_RPORT_ROLE_FCP_TARGET;
  662. rdata->ids.roles = roles;
  663. fc_rport_enter_rtv(rdata);
  664. } else {
  665. FC_RPORT_DBG(rdata, "Bad ELS response for PRLI command\n");
  666. fc_rport_error_retry(rdata, fp);
  667. }
  668. out:
  669. fc_frame_free(fp);
  670. err:
  671. mutex_unlock(&rdata->rp_mutex);
  672. kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
  673. }
  674. /**
  675. * fc_rport_logo_resp() - Handler for logout (LOGO) responses
  676. * @sp: The sequence the LOGO was on
  677. * @fp: The LOGO response frame
  678. * @rdata_arg: The remote port that sent the LOGO response
  679. *
  680. * Locking Note: This function will be called without the rport lock
  681. * held, but it will lock, call an _enter_* function or fc_rport_error
  682. * and then unlock the rport.
  683. */
  684. static void fc_rport_logo_resp(struct fc_seq *sp, struct fc_frame *fp,
  685. void *rdata_arg)
  686. {
  687. struct fc_rport_priv *rdata = rdata_arg;
  688. u8 op;
  689. mutex_lock(&rdata->rp_mutex);
  690. FC_RPORT_DBG(rdata, "Received a LOGO %s\n", fc_els_resp_type(fp));
  691. if (rdata->rp_state != RPORT_ST_LOGO) {
  692. FC_RPORT_DBG(rdata, "Received a LOGO response, but in state "
  693. "%s\n", fc_rport_state(rdata));
  694. if (IS_ERR(fp))
  695. goto err;
  696. goto out;
  697. }
  698. if (IS_ERR(fp)) {
  699. fc_rport_error_retry(rdata, fp);
  700. goto err;
  701. }
  702. op = fc_frame_payload_op(fp);
  703. if (op != ELS_LS_ACC)
  704. FC_RPORT_DBG(rdata, "Bad ELS response op %x for LOGO command\n",
  705. op);
  706. fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
  707. out:
  708. fc_frame_free(fp);
  709. err:
  710. mutex_unlock(&rdata->rp_mutex);
  711. kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
  712. }
  713. /**
  714. * fc_rport_enter_prli() - Send Process Login (PRLI) request
  715. * @rdata: The remote port to send the PRLI request to
  716. *
  717. * Locking Note: The rport lock is expected to be held before calling
  718. * this routine.
  719. */
  720. static void fc_rport_enter_prli(struct fc_rport_priv *rdata)
  721. {
  722. struct fc_lport *lport = rdata->local_port;
  723. struct {
  724. struct fc_els_prli prli;
  725. struct fc_els_spp spp;
  726. } *pp;
  727. struct fc_frame *fp;
  728. /*
  729. * If the rport is one of the well known addresses
  730. * we skip PRLI and RTV and go straight to READY.
  731. */
  732. if (rdata->ids.port_id >= FC_FID_DOM_MGR) {
  733. fc_rport_enter_ready(rdata);
  734. return;
  735. }
  736. FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
  737. fc_rport_state(rdata));
  738. fc_rport_state_enter(rdata, RPORT_ST_PRLI);
  739. fp = fc_frame_alloc(lport, sizeof(*pp));
  740. if (!fp) {
  741. fc_rport_error_retry(rdata, fp);
  742. return;
  743. }
  744. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_PRLI,
  745. fc_rport_prli_resp, rdata,
  746. 2 * lport->r_a_tov))
  747. fc_rport_error_retry(rdata, NULL);
  748. else
  749. kref_get(&rdata->kref);
  750. }
  751. /**
  752. * fc_rport_els_rtv_resp() - Handler for Request Timeout Value (RTV) responses
  753. * @sp: The sequence the RTV was on
  754. * @fp: The RTV response frame
  755. * @rdata_arg: The remote port that sent the RTV response
  756. *
  757. * Many targets don't seem to support this.
  758. *
  759. * Locking Note: This function will be called without the rport lock
  760. * held, but it will lock, call an _enter_* function or fc_rport_error
  761. * and then unlock the rport.
  762. */
  763. static void fc_rport_rtv_resp(struct fc_seq *sp, struct fc_frame *fp,
  764. void *rdata_arg)
  765. {
  766. struct fc_rport_priv *rdata = rdata_arg;
  767. u8 op;
  768. mutex_lock(&rdata->rp_mutex);
  769. FC_RPORT_DBG(rdata, "Received a RTV %s\n", fc_els_resp_type(fp));
  770. if (rdata->rp_state != RPORT_ST_RTV) {
  771. FC_RPORT_DBG(rdata, "Received a RTV response, but in state "
  772. "%s\n", fc_rport_state(rdata));
  773. if (IS_ERR(fp))
  774. goto err;
  775. goto out;
  776. }
  777. if (IS_ERR(fp)) {
  778. fc_rport_error(rdata, fp);
  779. goto err;
  780. }
  781. op = fc_frame_payload_op(fp);
  782. if (op == ELS_LS_ACC) {
  783. struct fc_els_rtv_acc *rtv;
  784. u32 toq;
  785. u32 tov;
  786. rtv = fc_frame_payload_get(fp, sizeof(*rtv));
  787. if (rtv) {
  788. toq = ntohl(rtv->rtv_toq);
  789. tov = ntohl(rtv->rtv_r_a_tov);
  790. if (tov == 0)
  791. tov = 1;
  792. rdata->r_a_tov = tov;
  793. tov = ntohl(rtv->rtv_e_d_tov);
  794. if (toq & FC_ELS_RTV_EDRES)
  795. tov /= 1000000;
  796. if (tov == 0)
  797. tov = 1;
  798. rdata->e_d_tov = tov;
  799. }
  800. }
  801. fc_rport_enter_ready(rdata);
  802. out:
  803. fc_frame_free(fp);
  804. err:
  805. mutex_unlock(&rdata->rp_mutex);
  806. kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
  807. }
  808. /**
  809. * fc_rport_enter_rtv() - Send Request Timeout Value (RTV) request
  810. * @rdata: The remote port to send the RTV request to
  811. *
  812. * Locking Note: The rport lock is expected to be held before calling
  813. * this routine.
  814. */
  815. static void fc_rport_enter_rtv(struct fc_rport_priv *rdata)
  816. {
  817. struct fc_frame *fp;
  818. struct fc_lport *lport = rdata->local_port;
  819. FC_RPORT_DBG(rdata, "Port entered RTV state from %s state\n",
  820. fc_rport_state(rdata));
  821. fc_rport_state_enter(rdata, RPORT_ST_RTV);
  822. fp = fc_frame_alloc(lport, sizeof(struct fc_els_rtv));
  823. if (!fp) {
  824. fc_rport_error_retry(rdata, fp);
  825. return;
  826. }
  827. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_RTV,
  828. fc_rport_rtv_resp, rdata,
  829. 2 * lport->r_a_tov))
  830. fc_rport_error_retry(rdata, NULL);
  831. else
  832. kref_get(&rdata->kref);
  833. }
  834. /**
  835. * fc_rport_enter_logo() - Send a logout (LOGO) request
  836. * @rdata: The remote port to send the LOGO request to
  837. *
  838. * Locking Note: The rport lock is expected to be held before calling
  839. * this routine.
  840. */
  841. static void fc_rport_enter_logo(struct fc_rport_priv *rdata)
  842. {
  843. struct fc_lport *lport = rdata->local_port;
  844. struct fc_frame *fp;
  845. FC_RPORT_DBG(rdata, "Port entered LOGO state from %s state\n",
  846. fc_rport_state(rdata));
  847. fc_rport_state_enter(rdata, RPORT_ST_LOGO);
  848. fp = fc_frame_alloc(lport, sizeof(struct fc_els_logo));
  849. if (!fp) {
  850. fc_rport_error_retry(rdata, fp);
  851. return;
  852. }
  853. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_LOGO,
  854. fc_rport_logo_resp, rdata,
  855. 2 * lport->r_a_tov))
  856. fc_rport_error_retry(rdata, NULL);
  857. else
  858. kref_get(&rdata->kref);
  859. }
  860. /**
  861. * fc_rport_els_adisc_resp() - Handler for Address Discovery (ADISC) responses
  862. * @sp: The sequence the ADISC response was on
  863. * @fp: The ADISC response frame
  864. * @rdata_arg: The remote port that sent the ADISC response
  865. *
  866. * Locking Note: This function will be called without the rport lock
  867. * held, but it will lock, call an _enter_* function or fc_rport_error
  868. * and then unlock the rport.
  869. */
  870. static void fc_rport_adisc_resp(struct fc_seq *sp, struct fc_frame *fp,
  871. void *rdata_arg)
  872. {
  873. struct fc_rport_priv *rdata = rdata_arg;
  874. struct fc_els_adisc *adisc;
  875. u8 op;
  876. mutex_lock(&rdata->rp_mutex);
  877. FC_RPORT_DBG(rdata, "Received a ADISC response\n");
  878. if (rdata->rp_state != RPORT_ST_ADISC) {
  879. FC_RPORT_DBG(rdata, "Received a ADISC resp but in state %s\n",
  880. fc_rport_state(rdata));
  881. if (IS_ERR(fp))
  882. goto err;
  883. goto out;
  884. }
  885. if (IS_ERR(fp)) {
  886. fc_rport_error(rdata, fp);
  887. goto err;
  888. }
  889. /*
  890. * If address verification failed. Consider us logged out of the rport.
  891. * Since the rport is still in discovery, we want to be
  892. * logged in, so go to PLOGI state. Otherwise, go back to READY.
  893. */
  894. op = fc_frame_payload_op(fp);
  895. adisc = fc_frame_payload_get(fp, sizeof(*adisc));
  896. if (op != ELS_LS_ACC || !adisc ||
  897. ntoh24(adisc->adisc_port_id) != rdata->ids.port_id ||
  898. get_unaligned_be64(&adisc->adisc_wwpn) != rdata->ids.port_name ||
  899. get_unaligned_be64(&adisc->adisc_wwnn) != rdata->ids.node_name) {
  900. FC_RPORT_DBG(rdata, "ADISC error or mismatch\n");
  901. fc_rport_enter_plogi(rdata);
  902. } else {
  903. FC_RPORT_DBG(rdata, "ADISC OK\n");
  904. fc_rport_enter_ready(rdata);
  905. }
  906. out:
  907. fc_frame_free(fp);
  908. err:
  909. mutex_unlock(&rdata->rp_mutex);
  910. kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy);
  911. }
  912. /**
  913. * fc_rport_enter_adisc() - Send Address Discover (ADISC) request
  914. * @rdata: The remote port to send the ADISC request to
  915. *
  916. * Locking Note: The rport lock is expected to be held before calling
  917. * this routine.
  918. */
  919. static void fc_rport_enter_adisc(struct fc_rport_priv *rdata)
  920. {
  921. struct fc_lport *lport = rdata->local_port;
  922. struct fc_frame *fp;
  923. FC_RPORT_DBG(rdata, "sending ADISC from %s state\n",
  924. fc_rport_state(rdata));
  925. fc_rport_state_enter(rdata, RPORT_ST_ADISC);
  926. fp = fc_frame_alloc(lport, sizeof(struct fc_els_adisc));
  927. if (!fp) {
  928. fc_rport_error_retry(rdata, fp);
  929. return;
  930. }
  931. if (!lport->tt.elsct_send(lport, rdata->ids.port_id, fp, ELS_ADISC,
  932. fc_rport_adisc_resp, rdata,
  933. 2 * lport->r_a_tov))
  934. fc_rport_error_retry(rdata, NULL);
  935. else
  936. kref_get(&rdata->kref);
  937. }
  938. /**
  939. * fc_rport_recv_adisc_req() - Handler for Address Discovery (ADISC) requests
  940. * @rdata: The remote port that sent the ADISC request
  941. * @sp: The sequence the ADISC request was on
  942. * @in_fp: The ADISC request frame
  943. *
  944. * Locking Note: Called with the lport and rport locks held.
  945. */
  946. static void fc_rport_recv_adisc_req(struct fc_rport_priv *rdata,
  947. struct fc_seq *sp, struct fc_frame *in_fp)
  948. {
  949. struct fc_lport *lport = rdata->local_port;
  950. struct fc_frame *fp;
  951. struct fc_exch *ep = fc_seq_exch(sp);
  952. struct fc_els_adisc *adisc;
  953. struct fc_seq_els_data rjt_data;
  954. u32 f_ctl;
  955. FC_RPORT_DBG(rdata, "Received ADISC request\n");
  956. adisc = fc_frame_payload_get(in_fp, sizeof(*adisc));
  957. if (!adisc) {
  958. rjt_data.fp = NULL;
  959. rjt_data.reason = ELS_RJT_PROT;
  960. rjt_data.explan = ELS_EXPL_INV_LEN;
  961. lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
  962. goto drop;
  963. }
  964. fp = fc_frame_alloc(lport, sizeof(*adisc));
  965. if (!fp)
  966. goto drop;
  967. fc_adisc_fill(lport, fp);
  968. adisc = fc_frame_payload_get(fp, sizeof(*adisc));
  969. adisc->adisc_cmd = ELS_LS_ACC;
  970. sp = lport->tt.seq_start_next(sp);
  971. f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT;
  972. fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
  973. FC_TYPE_ELS, f_ctl, 0);
  974. lport->tt.seq_send(lport, sp, fp);
  975. drop:
  976. fc_frame_free(in_fp);
  977. }
  978. /**
  979. * fc_rport_recv_rls_req() - Handle received Read Link Status request
  980. * @rdata: The remote port that sent the RLS request
  981. * @sp: The sequence that the RLS was on
  982. * @rx_fp: The PRLI request frame
  983. *
  984. * Locking Note: The rport lock is expected to be held before calling
  985. * this function.
  986. */
  987. static void fc_rport_recv_rls_req(struct fc_rport_priv *rdata,
  988. struct fc_seq *sp, struct fc_frame *rx_fp)
  989. {
  990. struct fc_lport *lport = rdata->local_port;
  991. struct fc_frame *fp;
  992. struct fc_exch *ep = fc_seq_exch(sp);
  993. struct fc_els_rls *rls;
  994. struct fc_els_rls_resp *rsp;
  995. struct fc_els_lesb *lesb;
  996. struct fc_seq_els_data rjt_data;
  997. struct fc_host_statistics *hst;
  998. u32 f_ctl;
  999. FC_RPORT_DBG(rdata, "Received RLS request while in state %s\n",
  1000. fc_rport_state(rdata));
  1001. rls = fc_frame_payload_get(rx_fp, sizeof(*rls));
  1002. if (!rls) {
  1003. rjt_data.reason = ELS_RJT_PROT;
  1004. rjt_data.explan = ELS_EXPL_INV_LEN;
  1005. goto out_rjt;
  1006. }
  1007. fp = fc_frame_alloc(lport, sizeof(*rsp));
  1008. if (!fp) {
  1009. rjt_data.reason = ELS_RJT_UNAB;
  1010. rjt_data.explan = ELS_EXPL_INSUF_RES;
  1011. goto out_rjt;
  1012. }
  1013. rsp = fc_frame_payload_get(fp, sizeof(*rsp));
  1014. memset(rsp, 0, sizeof(*rsp));
  1015. rsp->rls_cmd = ELS_LS_ACC;
  1016. lesb = &rsp->rls_lesb;
  1017. if (lport->tt.get_lesb) {
  1018. /* get LESB from LLD if it supports it */
  1019. lport->tt.get_lesb(lport, lesb);
  1020. } else {
  1021. fc_get_host_stats(lport->host);
  1022. hst = &lport->host_stats;
  1023. lesb->lesb_link_fail = htonl(hst->link_failure_count);
  1024. lesb->lesb_sync_loss = htonl(hst->loss_of_sync_count);
  1025. lesb->lesb_sig_loss = htonl(hst->loss_of_signal_count);
  1026. lesb->lesb_prim_err = htonl(hst->prim_seq_protocol_err_count);
  1027. lesb->lesb_inv_word = htonl(hst->invalid_tx_word_count);
  1028. lesb->lesb_inv_crc = htonl(hst->invalid_crc_count);
  1029. }
  1030. sp = lport->tt.seq_start_next(sp);
  1031. f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ;
  1032. fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
  1033. FC_TYPE_ELS, f_ctl, 0);
  1034. lport->tt.seq_send(lport, sp, fp);
  1035. goto out;
  1036. out_rjt:
  1037. rjt_data.fp = NULL;
  1038. lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
  1039. out:
  1040. fc_frame_free(rx_fp);
  1041. }
  1042. /**
  1043. * fc_rport_recv_els_req() - Handler for validated ELS requests
  1044. * @lport: The local port that received the ELS request
  1045. * @sp: The sequence that the ELS request was on
  1046. * @fp: The ELS request frame
  1047. *
  1048. * Handle incoming ELS requests that require port login.
  1049. * The ELS opcode has already been validated by the caller.
  1050. *
  1051. * Locking Note: Called with the lport lock held.
  1052. */
  1053. static void fc_rport_recv_els_req(struct fc_lport *lport,
  1054. struct fc_seq *sp, struct fc_frame *fp)
  1055. {
  1056. struct fc_rport_priv *rdata;
  1057. struct fc_frame_header *fh;
  1058. struct fc_seq_els_data els_data;
  1059. els_data.fp = NULL;
  1060. els_data.reason = ELS_RJT_UNAB;
  1061. els_data.explan = ELS_EXPL_PLOGI_REQD;
  1062. fh = fc_frame_header_get(fp);
  1063. mutex_lock(&lport->disc.disc_mutex);
  1064. rdata = lport->tt.rport_lookup(lport, ntoh24(fh->fh_s_id));
  1065. if (!rdata) {
  1066. mutex_unlock(&lport->disc.disc_mutex);
  1067. goto reject;
  1068. }
  1069. mutex_lock(&rdata->rp_mutex);
  1070. mutex_unlock(&lport->disc.disc_mutex);
  1071. switch (rdata->rp_state) {
  1072. case RPORT_ST_PRLI:
  1073. case RPORT_ST_RTV:
  1074. case RPORT_ST_READY:
  1075. case RPORT_ST_ADISC:
  1076. break;
  1077. default:
  1078. mutex_unlock(&rdata->rp_mutex);
  1079. goto reject;
  1080. }
  1081. switch (fc_frame_payload_op(fp)) {
  1082. case ELS_PRLI:
  1083. fc_rport_recv_prli_req(rdata, sp, fp);
  1084. break;
  1085. case ELS_PRLO:
  1086. fc_rport_recv_prlo_req(rdata, sp, fp);
  1087. break;
  1088. case ELS_ADISC:
  1089. fc_rport_recv_adisc_req(rdata, sp, fp);
  1090. break;
  1091. case ELS_RRQ:
  1092. els_data.fp = fp;
  1093. lport->tt.seq_els_rsp_send(sp, ELS_RRQ, &els_data);
  1094. break;
  1095. case ELS_REC:
  1096. els_data.fp = fp;
  1097. lport->tt.seq_els_rsp_send(sp, ELS_REC, &els_data);
  1098. break;
  1099. case ELS_RLS:
  1100. fc_rport_recv_rls_req(rdata, sp, fp);
  1101. break;
  1102. default:
  1103. fc_frame_free(fp); /* can't happen */
  1104. break;
  1105. }
  1106. mutex_unlock(&rdata->rp_mutex);
  1107. return;
  1108. reject:
  1109. lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &els_data);
  1110. fc_frame_free(fp);
  1111. }
  1112. /**
  1113. * fc_rport_recv_req() - Handler for requests
  1114. * @sp: The sequence the request was on
  1115. * @fp: The request frame
  1116. * @lport: The local port that received the request
  1117. *
  1118. * Locking Note: Called with the lport lock held.
  1119. */
  1120. void fc_rport_recv_req(struct fc_seq *sp, struct fc_frame *fp,
  1121. struct fc_lport *lport)
  1122. {
  1123. struct fc_seq_els_data els_data;
  1124. /*
  1125. * Handle PLOGI and LOGO requests separately, since they
  1126. * don't require prior login.
  1127. * Check for unsupported opcodes first and reject them.
  1128. * For some ops, it would be incorrect to reject with "PLOGI required".
  1129. */
  1130. switch (fc_frame_payload_op(fp)) {
  1131. case ELS_PLOGI:
  1132. fc_rport_recv_plogi_req(lport, sp, fp);
  1133. break;
  1134. case ELS_LOGO:
  1135. fc_rport_recv_logo_req(lport, sp, fp);
  1136. break;
  1137. case ELS_PRLI:
  1138. case ELS_PRLO:
  1139. case ELS_ADISC:
  1140. case ELS_RRQ:
  1141. case ELS_REC:
  1142. case ELS_RLS:
  1143. fc_rport_recv_els_req(lport, sp, fp);
  1144. break;
  1145. default:
  1146. fc_frame_free(fp);
  1147. els_data.fp = NULL;
  1148. els_data.reason = ELS_RJT_UNSUP;
  1149. els_data.explan = ELS_EXPL_NONE;
  1150. lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &els_data);
  1151. break;
  1152. }
  1153. }
  1154. /**
  1155. * fc_rport_recv_plogi_req() - Handler for Port Login (PLOGI) requests
  1156. * @lport: The local port that received the PLOGI request
  1157. * @sp: The sequence that the PLOGI request was on
  1158. * @rx_fp: The PLOGI request frame
  1159. *
  1160. * Locking Note: The rport lock is held before calling this function.
  1161. */
  1162. static void fc_rport_recv_plogi_req(struct fc_lport *lport,
  1163. struct fc_seq *sp, struct fc_frame *rx_fp)
  1164. {
  1165. struct fc_disc *disc;
  1166. struct fc_rport_priv *rdata;
  1167. struct fc_frame *fp = rx_fp;
  1168. struct fc_exch *ep;
  1169. struct fc_frame_header *fh;
  1170. struct fc_els_flogi *pl;
  1171. struct fc_seq_els_data rjt_data;
  1172. u32 sid, f_ctl;
  1173. rjt_data.fp = NULL;
  1174. fh = fc_frame_header_get(fp);
  1175. sid = ntoh24(fh->fh_s_id);
  1176. FC_RPORT_ID_DBG(lport, sid, "Received PLOGI request\n");
  1177. pl = fc_frame_payload_get(fp, sizeof(*pl));
  1178. if (!pl) {
  1179. FC_RPORT_ID_DBG(lport, sid, "Received PLOGI too short\n");
  1180. rjt_data.reason = ELS_RJT_PROT;
  1181. rjt_data.explan = ELS_EXPL_INV_LEN;
  1182. goto reject;
  1183. }
  1184. disc = &lport->disc;
  1185. mutex_lock(&disc->disc_mutex);
  1186. rdata = lport->tt.rport_create(lport, sid);
  1187. if (!rdata) {
  1188. mutex_unlock(&disc->disc_mutex);
  1189. rjt_data.reason = ELS_RJT_UNAB;
  1190. rjt_data.explan = ELS_EXPL_INSUF_RES;
  1191. goto reject;
  1192. }
  1193. mutex_lock(&rdata->rp_mutex);
  1194. mutex_unlock(&disc->disc_mutex);
  1195. rdata->ids.port_name = get_unaligned_be64(&pl->fl_wwpn);
  1196. rdata->ids.node_name = get_unaligned_be64(&pl->fl_wwnn);
  1197. /*
  1198. * If the rport was just created, possibly due to the incoming PLOGI,
  1199. * set the state appropriately and accept the PLOGI.
  1200. *
  1201. * If we had also sent a PLOGI, and if the received PLOGI is from a
  1202. * higher WWPN, we accept it, otherwise an LS_RJT is sent with reason
  1203. * "command already in progress".
  1204. *
  1205. * XXX TBD: If the session was ready before, the PLOGI should result in
  1206. * all outstanding exchanges being reset.
  1207. */
  1208. switch (rdata->rp_state) {
  1209. case RPORT_ST_INIT:
  1210. FC_RPORT_DBG(rdata, "Received PLOGI in INIT state\n");
  1211. break;
  1212. case RPORT_ST_PLOGI:
  1213. FC_RPORT_DBG(rdata, "Received PLOGI in PLOGI state\n");
  1214. if (rdata->ids.port_name < lport->wwpn) {
  1215. mutex_unlock(&rdata->rp_mutex);
  1216. rjt_data.reason = ELS_RJT_INPROG;
  1217. rjt_data.explan = ELS_EXPL_NONE;
  1218. goto reject;
  1219. }
  1220. break;
  1221. case RPORT_ST_PRLI:
  1222. case RPORT_ST_RTV:
  1223. case RPORT_ST_READY:
  1224. case RPORT_ST_ADISC:
  1225. FC_RPORT_DBG(rdata, "Received PLOGI in logged-in state %d "
  1226. "- ignored for now\n", rdata->rp_state);
  1227. /* XXX TBD - should reset */
  1228. break;
  1229. case RPORT_ST_DELETE:
  1230. case RPORT_ST_LOGO:
  1231. FC_RPORT_DBG(rdata, "Received PLOGI in state %s - send busy\n",
  1232. fc_rport_state(rdata));
  1233. mutex_unlock(&rdata->rp_mutex);
  1234. rjt_data.reason = ELS_RJT_BUSY;
  1235. rjt_data.explan = ELS_EXPL_NONE;
  1236. goto reject;
  1237. }
  1238. /*
  1239. * Get session payload size from incoming PLOGI.
  1240. */
  1241. rdata->maxframe_size = fc_plogi_get_maxframe(pl, lport->mfs);
  1242. fc_frame_free(rx_fp);
  1243. /*
  1244. * Send LS_ACC. If this fails, the originator should retry.
  1245. */
  1246. sp = lport->tt.seq_start_next(sp);
  1247. if (!sp)
  1248. goto out;
  1249. fp = fc_frame_alloc(lport, sizeof(*pl));
  1250. if (!fp)
  1251. goto out;
  1252. fc_plogi_fill(lport, fp, ELS_LS_ACC);
  1253. f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT;
  1254. ep = fc_seq_exch(sp);
  1255. fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
  1256. FC_TYPE_ELS, f_ctl, 0);
  1257. lport->tt.seq_send(lport, sp, fp);
  1258. fc_rport_enter_prli(rdata);
  1259. out:
  1260. mutex_unlock(&rdata->rp_mutex);
  1261. return;
  1262. reject:
  1263. lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
  1264. fc_frame_free(fp);
  1265. }
  1266. /**
  1267. * fc_rport_recv_prli_req() - Handler for process login (PRLI) requests
  1268. * @rdata: The remote port that sent the PRLI request
  1269. * @sp: The sequence that the PRLI was on
  1270. * @rx_fp: The PRLI request frame
  1271. *
  1272. * Locking Note: The rport lock is exected to be held before calling
  1273. * this function.
  1274. */
  1275. static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
  1276. struct fc_seq *sp, struct fc_frame *rx_fp)
  1277. {
  1278. struct fc_lport *lport = rdata->local_port;
  1279. struct fc_exch *ep;
  1280. struct fc_frame *fp;
  1281. struct fc_frame_header *fh;
  1282. struct {
  1283. struct fc_els_prli prli;
  1284. struct fc_els_spp spp;
  1285. } *pp;
  1286. struct fc_els_spp *rspp; /* request service param page */
  1287. struct fc_els_spp *spp; /* response spp */
  1288. unsigned int len;
  1289. unsigned int plen;
  1290. enum fc_els_spp_resp resp;
  1291. struct fc_seq_els_data rjt_data;
  1292. u32 f_ctl;
  1293. u32 fcp_parm;
  1294. u32 roles = FC_RPORT_ROLE_UNKNOWN;
  1295. rjt_data.fp = NULL;
  1296. fh = fc_frame_header_get(rx_fp);
  1297. FC_RPORT_DBG(rdata, "Received PRLI request while in state %s\n",
  1298. fc_rport_state(rdata));
  1299. len = fr_len(rx_fp) - sizeof(*fh);
  1300. pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
  1301. if (!pp)
  1302. goto reject_len;
  1303. plen = ntohs(pp->prli.prli_len);
  1304. if ((plen % 4) != 0 || plen > len || plen < 16)
  1305. goto reject_len;
  1306. if (plen < len)
  1307. len = plen;
  1308. plen = pp->prli.prli_spp_len;
  1309. if ((plen % 4) != 0 || plen < sizeof(*spp) ||
  1310. plen > len || len < sizeof(*pp) || plen < 12)
  1311. goto reject_len;
  1312. rspp = &pp->spp;
  1313. fp = fc_frame_alloc(lport, len);
  1314. if (!fp) {
  1315. rjt_data.reason = ELS_RJT_UNAB;
  1316. rjt_data.explan = ELS_EXPL_INSUF_RES;
  1317. goto reject;
  1318. }
  1319. sp = lport->tt.seq_start_next(sp);
  1320. WARN_ON(!sp);
  1321. pp = fc_frame_payload_get(fp, len);
  1322. WARN_ON(!pp);
  1323. memset(pp, 0, len);
  1324. pp->prli.prli_cmd = ELS_LS_ACC;
  1325. pp->prli.prli_spp_len = plen;
  1326. pp->prli.prli_len = htons(len);
  1327. len -= sizeof(struct fc_els_prli);
  1328. /* reinitialize remote port roles */
  1329. rdata->ids.roles = FC_RPORT_ROLE_UNKNOWN;
  1330. /*
  1331. * Go through all the service parameter pages and build
  1332. * response. If plen indicates longer SPP than standard,
  1333. * use that. The entire response has been pre-cleared above.
  1334. */
  1335. spp = &pp->spp;
  1336. while (len >= plen) {
  1337. spp->spp_type = rspp->spp_type;
  1338. spp->spp_type_ext = rspp->spp_type_ext;
  1339. spp->spp_flags = rspp->spp_flags & FC_SPP_EST_IMG_PAIR;
  1340. resp = FC_SPP_RESP_ACK;
  1341. switch (rspp->spp_type) {
  1342. case 0: /* common to all FC-4 types */
  1343. break;
  1344. case FC_TYPE_FCP:
  1345. fcp_parm = ntohl(rspp->spp_params);
  1346. if (fcp_parm & FCP_SPPF_RETRY)
  1347. rdata->flags |= FC_RP_FLAGS_RETRY;
  1348. rdata->supported_classes = FC_COS_CLASS3;
  1349. if (fcp_parm & FCP_SPPF_INIT_FCN)
  1350. roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  1351. if (fcp_parm & FCP_SPPF_TARG_FCN)
  1352. roles |= FC_RPORT_ROLE_FCP_TARGET;
  1353. rdata->ids.roles = roles;
  1354. spp->spp_params = htonl(lport->service_params);
  1355. break;
  1356. default:
  1357. resp = FC_SPP_RESP_INVL;
  1358. break;
  1359. }
  1360. spp->spp_flags |= resp;
  1361. len -= plen;
  1362. rspp = (struct fc_els_spp *)((char *)rspp + plen);
  1363. spp = (struct fc_els_spp *)((char *)spp + plen);
  1364. }
  1365. /*
  1366. * Send LS_ACC. If this fails, the originator should retry.
  1367. */
  1368. f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ;
  1369. f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT;
  1370. ep = fc_seq_exch(sp);
  1371. fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
  1372. FC_TYPE_ELS, f_ctl, 0);
  1373. lport->tt.seq_send(lport, sp, fp);
  1374. switch (rdata->rp_state) {
  1375. case RPORT_ST_PRLI:
  1376. fc_rport_enter_ready(rdata);
  1377. break;
  1378. default:
  1379. break;
  1380. }
  1381. goto drop;
  1382. reject_len:
  1383. rjt_data.reason = ELS_RJT_PROT;
  1384. rjt_data.explan = ELS_EXPL_INV_LEN;
  1385. reject:
  1386. lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
  1387. drop:
  1388. fc_frame_free(rx_fp);
  1389. }
  1390. /**
  1391. * fc_rport_recv_prlo_req() - Handler for process logout (PRLO) requests
  1392. * @rdata: The remote port that sent the PRLO request
  1393. * @sp: The sequence that the PRLO was on
  1394. * @rx_fp: The PRLO request frame
  1395. *
  1396. * Locking Note: The rport lock is exected to be held before calling
  1397. * this function.
  1398. */
  1399. static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
  1400. struct fc_seq *sp,
  1401. struct fc_frame *rx_fp)
  1402. {
  1403. struct fc_lport *lport = rdata->local_port;
  1404. struct fc_frame_header *fh;
  1405. struct fc_exch *ep;
  1406. struct fc_frame *fp;
  1407. struct {
  1408. struct fc_els_prlo prlo;
  1409. struct fc_els_spp spp;
  1410. } *pp;
  1411. struct fc_els_spp *rspp; /* request service param page */
  1412. struct fc_els_spp *spp; /* response spp */
  1413. unsigned int len;
  1414. unsigned int plen;
  1415. u32 f_ctl;
  1416. struct fc_seq_els_data rjt_data;
  1417. rjt_data.fp = NULL;
  1418. fh = fc_frame_header_get(rx_fp);
  1419. FC_RPORT_DBG(rdata, "Received PRLO request while in state %s\n",
  1420. fc_rport_state(rdata));
  1421. len = fr_len(rx_fp) - sizeof(*fh);
  1422. pp = fc_frame_payload_get(rx_fp, sizeof(*pp));
  1423. if (!pp)
  1424. goto reject_len;
  1425. plen = ntohs(pp->prlo.prlo_len);
  1426. if (plen != 20)
  1427. goto reject_len;
  1428. if (plen < len)
  1429. len = plen;
  1430. rspp = &pp->spp;
  1431. fp = fc_frame_alloc(lport, len);
  1432. if (!fp) {
  1433. rjt_data.reason = ELS_RJT_UNAB;
  1434. rjt_data.explan = ELS_EXPL_INSUF_RES;
  1435. goto reject;
  1436. }
  1437. sp = lport->tt.seq_start_next(sp);
  1438. WARN_ON(!sp);
  1439. pp = fc_frame_payload_get(fp, len);
  1440. WARN_ON(!pp);
  1441. memset(pp, 0, len);
  1442. pp->prlo.prlo_cmd = ELS_LS_ACC;
  1443. pp->prlo.prlo_obs = 0x10;
  1444. pp->prlo.prlo_len = htons(len);
  1445. spp = &pp->spp;
  1446. spp->spp_type = rspp->spp_type;
  1447. spp->spp_type_ext = rspp->spp_type_ext;
  1448. spp->spp_flags = FC_SPP_RESP_ACK;
  1449. fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
  1450. f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ;
  1451. f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT;
  1452. ep = fc_seq_exch(sp);
  1453. fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid,
  1454. FC_TYPE_ELS, f_ctl, 0);
  1455. lport->tt.seq_send(lport, sp, fp);
  1456. goto drop;
  1457. reject_len:
  1458. rjt_data.reason = ELS_RJT_PROT;
  1459. rjt_data.explan = ELS_EXPL_INV_LEN;
  1460. reject:
  1461. lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data);
  1462. drop:
  1463. fc_frame_free(rx_fp);
  1464. }
  1465. /**
  1466. * fc_rport_recv_logo_req() - Handler for logout (LOGO) requests
  1467. * @lport: The local port that received the LOGO request
  1468. * @sp: The sequence that the LOGO request was on
  1469. * @fp: The LOGO request frame
  1470. *
  1471. * Locking Note: The rport lock is exected to be held before calling
  1472. * this function.
  1473. */
  1474. static void fc_rport_recv_logo_req(struct fc_lport *lport,
  1475. struct fc_seq *sp,
  1476. struct fc_frame *fp)
  1477. {
  1478. struct fc_frame_header *fh;
  1479. struct fc_rport_priv *rdata;
  1480. u32 sid;
  1481. lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
  1482. fh = fc_frame_header_get(fp);
  1483. sid = ntoh24(fh->fh_s_id);
  1484. mutex_lock(&lport->disc.disc_mutex);
  1485. rdata = lport->tt.rport_lookup(lport, sid);
  1486. if (rdata) {
  1487. mutex_lock(&rdata->rp_mutex);
  1488. FC_RPORT_DBG(rdata, "Received LOGO request while in state %s\n",
  1489. fc_rport_state(rdata));
  1490. fc_rport_enter_delete(rdata, RPORT_EV_LOGO);
  1491. mutex_unlock(&rdata->rp_mutex);
  1492. } else
  1493. FC_RPORT_ID_DBG(lport, sid,
  1494. "Received LOGO from non-logged-in port\n");
  1495. mutex_unlock(&lport->disc.disc_mutex);
  1496. fc_frame_free(fp);
  1497. }
  1498. /**
  1499. * fc_rport_flush_queue() - Flush the rport_event_queue
  1500. */
  1501. static void fc_rport_flush_queue(void)
  1502. {
  1503. flush_workqueue(rport_event_queue);
  1504. }
  1505. /**
  1506. * fc_rport_init() - Initialize the remote port layer for a local port
  1507. * @lport: The local port to initialize the remote port layer for
  1508. */
  1509. int fc_rport_init(struct fc_lport *lport)
  1510. {
  1511. if (!lport->tt.rport_lookup)
  1512. lport->tt.rport_lookup = fc_rport_lookup;
  1513. if (!lport->tt.rport_create)
  1514. lport->tt.rport_create = fc_rport_create;
  1515. if (!lport->tt.rport_login)
  1516. lport->tt.rport_login = fc_rport_login;
  1517. if (!lport->tt.rport_logoff)
  1518. lport->tt.rport_logoff = fc_rport_logoff;
  1519. if (!lport->tt.rport_recv_req)
  1520. lport->tt.rport_recv_req = fc_rport_recv_req;
  1521. if (!lport->tt.rport_flush_queue)
  1522. lport->tt.rport_flush_queue = fc_rport_flush_queue;
  1523. if (!lport->tt.rport_destroy)
  1524. lport->tt.rport_destroy = fc_rport_destroy;
  1525. return 0;
  1526. }
  1527. EXPORT_SYMBOL(fc_rport_init);
  1528. /**
  1529. * fc_setup_rport() - Initialize the rport_event_queue
  1530. */
  1531. int fc_setup_rport()
  1532. {
  1533. rport_event_queue = create_singlethread_workqueue("fc_rport_eq");
  1534. if (!rport_event_queue)
  1535. return -ENOMEM;
  1536. return 0;
  1537. }
  1538. /**
  1539. * fc_destroy_rport() - Destroy the rport_event_queue
  1540. */
  1541. void fc_destroy_rport()
  1542. {
  1543. destroy_workqueue(rport_event_queue);
  1544. }
  1545. /**
  1546. * fc_rport_terminate_io() - Stop all outstanding I/O on a remote port
  1547. * @rport: The remote port whose I/O should be terminated
  1548. */
  1549. void fc_rport_terminate_io(struct fc_rport *rport)
  1550. {
  1551. struct fc_rport_libfc_priv *rpriv = rport->dd_data;
  1552. struct fc_lport *lport = rpriv->local_port;
  1553. lport->tt.exch_mgr_reset(lport, 0, rport->port_id);
  1554. lport->tt.exch_mgr_reset(lport, rport->port_id, 0);
  1555. }
  1556. EXPORT_SYMBOL(fc_rport_terminate_io);