efc_els.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
  4. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
  5. */
  6. /*
  7. * Functions to build and send ELS/CT/BLS commands and responses.
  8. */
  9. #include "efc.h"
  10. #include "efc_els.h"
  11. #include "../libefc_sli/sli4.h"
  12. #define EFC_LOG_ENABLE_ELS_TRACE(efc) \
  13. (((efc) != NULL) ? (((efc)->logmask & (1U << 1)) != 0) : 0)
  14. #define node_els_trace() \
  15. do { \
  16. if (EFC_LOG_ENABLE_ELS_TRACE(efc)) \
  17. efc_log_info(efc, "[%s] %-20s\n", \
  18. node->display_name, __func__); \
  19. } while (0)
  20. #define els_io_printf(els, fmt, ...) \
  21. efc_log_err((struct efc *)els->node->efc,\
  22. "[%s] %-8s " fmt, \
  23. els->node->display_name,\
  24. els->display_name, ##__VA_ARGS__)
  25. #define EFC_ELS_RSP_LEN 1024
  26. #define EFC_ELS_GID_PT_RSP_LEN 8096
  27. struct efc_els_io_req *
  28. efc_els_io_alloc(struct efc_node *node, u32 reqlen)
  29. {
  30. return efc_els_io_alloc_size(node, reqlen, EFC_ELS_RSP_LEN);
  31. }
  32. struct efc_els_io_req *
  33. efc_els_io_alloc_size(struct efc_node *node, u32 reqlen, u32 rsplen)
  34. {
  35. struct efc *efc;
  36. struct efc_els_io_req *els;
  37. unsigned long flags = 0;
  38. efc = node->efc;
  39. if (!node->els_io_enabled) {
  40. efc_log_err(efc, "els io alloc disabled\n");
  41. return NULL;
  42. }
  43. els = mempool_alloc(efc->els_io_pool, GFP_ATOMIC);
  44. if (!els) {
  45. atomic_add_return(1, &efc->els_io_alloc_failed_count);
  46. return NULL;
  47. }
  48. /* initialize refcount */
  49. kref_init(&els->ref);
  50. els->release = _efc_els_io_free;
  51. /* populate generic io fields */
  52. els->node = node;
  53. /* now allocate DMA for request and response */
  54. els->io.req.size = reqlen;
  55. els->io.req.virt = dma_alloc_coherent(&efc->pci->dev, els->io.req.size,
  56. &els->io.req.phys, GFP_KERNEL);
  57. if (!els->io.req.virt) {
  58. mempool_free(els, efc->els_io_pool);
  59. return NULL;
  60. }
  61. els->io.rsp.size = rsplen;
  62. els->io.rsp.virt = dma_alloc_coherent(&efc->pci->dev, els->io.rsp.size,
  63. &els->io.rsp.phys, GFP_KERNEL);
  64. if (!els->io.rsp.virt) {
  65. dma_free_coherent(&efc->pci->dev, els->io.req.size,
  66. els->io.req.virt, els->io.req.phys);
  67. mempool_free(els, efc->els_io_pool);
  68. els = NULL;
  69. }
  70. if (els) {
  71. /* initialize fields */
  72. els->els_retries_remaining = EFC_FC_ELS_DEFAULT_RETRIES;
  73. /* add els structure to ELS IO list */
  74. INIT_LIST_HEAD(&els->list_entry);
  75. spin_lock_irqsave(&node->els_ios_lock, flags);
  76. list_add_tail(&els->list_entry, &node->els_ios_list);
  77. spin_unlock_irqrestore(&node->els_ios_lock, flags);
  78. }
  79. return els;
  80. }
  81. void
  82. efc_els_io_free(struct efc_els_io_req *els)
  83. {
  84. kref_put(&els->ref, els->release);
  85. }
  86. void
  87. _efc_els_io_free(struct kref *arg)
  88. {
  89. struct efc_els_io_req *els =
  90. container_of(arg, struct efc_els_io_req, ref);
  91. struct efc *efc;
  92. struct efc_node *node;
  93. int send_empty_event = false;
  94. unsigned long flags = 0;
  95. node = els->node;
  96. efc = node->efc;
  97. spin_lock_irqsave(&node->els_ios_lock, flags);
  98. list_del(&els->list_entry);
  99. /* Send list empty event if the IO allocator
  100. * is disabled, and the list is empty
  101. * If node->els_io_enabled was not checked,
  102. * the event would be posted continually
  103. */
  104. send_empty_event = (!node->els_io_enabled &&
  105. list_empty(&node->els_ios_list));
  106. spin_unlock_irqrestore(&node->els_ios_lock, flags);
  107. /* free ELS request and response buffers */
  108. dma_free_coherent(&efc->pci->dev, els->io.rsp.size,
  109. els->io.rsp.virt, els->io.rsp.phys);
  110. dma_free_coherent(&efc->pci->dev, els->io.req.size,
  111. els->io.req.virt, els->io.req.phys);
  112. mempool_free(els, efc->els_io_pool);
  113. if (send_empty_event)
  114. efc_scsi_io_list_empty(node->efc, node);
  115. }
  116. static void
  117. efc_els_retry(struct efc_els_io_req *els);
  118. static void
  119. efc_els_delay_timer_cb(struct timer_list *t)
  120. {
  121. struct efc_els_io_req *els = from_timer(els, t, delay_timer);
  122. /* Retry delay timer expired, retry the ELS request */
  123. efc_els_retry(els);
  124. }
  125. static int
  126. efc_els_req_cb(void *arg, u32 length, int status, u32 ext_status)
  127. {
  128. struct efc_els_io_req *els;
  129. struct efc_node *node;
  130. struct efc *efc;
  131. struct efc_node_cb cbdata;
  132. u32 reason_code;
  133. els = arg;
  134. node = els->node;
  135. efc = node->efc;
  136. if (status)
  137. els_io_printf(els, "status x%x ext x%x\n", status, ext_status);
  138. /* set the response len element of els->rsp */
  139. els->io.rsp.len = length;
  140. cbdata.status = status;
  141. cbdata.ext_status = ext_status;
  142. cbdata.header = NULL;
  143. cbdata.els_rsp = els->io.rsp;
  144. /* set the response len element of els->rsp */
  145. cbdata.rsp_len = length;
  146. /* FW returns the number of bytes received on the link in
  147. * the WCQE, not the amount placed in the buffer; use this info to
  148. * check if there was an overrun.
  149. */
  150. if (length > els->io.rsp.size) {
  151. efc_log_warn(efc,
  152. "ELS response returned len=%d > buflen=%zu\n",
  153. length, els->io.rsp.size);
  154. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
  155. return 0;
  156. }
  157. /* Post event to ELS IO object */
  158. switch (status) {
  159. case SLI4_FC_WCQE_STATUS_SUCCESS:
  160. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_OK, &cbdata);
  161. break;
  162. case SLI4_FC_WCQE_STATUS_LS_RJT:
  163. reason_code = (ext_status >> 16) & 0xff;
  164. /* delay and retry if reason code is Logical Busy */
  165. switch (reason_code) {
  166. case ELS_RJT_BUSY:
  167. els->node->els_req_cnt--;
  168. els_io_printf(els,
  169. "LS_RJT Logical Busy, delay and retry\n");
  170. timer_setup(&els->delay_timer,
  171. efc_els_delay_timer_cb, 0);
  172. mod_timer(&els->delay_timer,
  173. jiffies + msecs_to_jiffies(5000));
  174. break;
  175. default:
  176. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_RJT,
  177. &cbdata);
  178. break;
  179. }
  180. break;
  181. case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
  182. switch (ext_status) {
  183. case SLI4_FC_LOCAL_REJECT_SEQUENCE_TIMEOUT:
  184. efc_els_retry(els);
  185. break;
  186. default:
  187. efc_log_err(efc, "LOCAL_REJECT with ext status:%x\n",
  188. ext_status);
  189. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL,
  190. &cbdata);
  191. break;
  192. }
  193. break;
  194. default: /* Other error */
  195. efc_log_warn(efc, "els req failed status x%x, ext_status x%x\n",
  196. status, ext_status);
  197. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
  198. break;
  199. }
  200. return 0;
  201. }
  202. void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status,
  203. u32 ext_status)
  204. {
  205. struct efc_els_io_req *els =
  206. container_of(io, struct efc_els_io_req, io);
  207. WARN_ON_ONCE(!els->cb);
  208. ((efc_hw_srrs_cb_t)els->cb) (els, len, status, ext_status);
  209. }
  210. static int efc_els_send_req(struct efc_node *node, struct efc_els_io_req *els,
  211. enum efc_disc_io_type io_type)
  212. {
  213. int rc = 0;
  214. struct efc *efc = node->efc;
  215. struct efc_node_cb cbdata;
  216. /* update ELS request counter */
  217. els->node->els_req_cnt++;
  218. /* Prepare the IO request details */
  219. els->io.io_type = io_type;
  220. els->io.xmit_len = els->io.req.size;
  221. els->io.rsp_len = els->io.rsp.size;
  222. els->io.rpi = node->rnode.indicator;
  223. els->io.vpi = node->nport->indicator;
  224. els->io.s_id = node->nport->fc_id;
  225. els->io.d_id = node->rnode.fc_id;
  226. if (node->rnode.attached)
  227. els->io.rpi_registered = true;
  228. els->cb = efc_els_req_cb;
  229. rc = efc->tt.send_els(efc, &els->io);
  230. if (!rc)
  231. return rc;
  232. cbdata.status = EFC_STATUS_INVALID;
  233. cbdata.ext_status = EFC_STATUS_INVALID;
  234. cbdata.els_rsp = els->io.rsp;
  235. efc_log_err(efc, "efc_els_send failed: %d\n", rc);
  236. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
  237. return rc;
  238. }
  239. static void
  240. efc_els_retry(struct efc_els_io_req *els)
  241. {
  242. struct efc *efc;
  243. struct efc_node_cb cbdata;
  244. u32 rc;
  245. efc = els->node->efc;
  246. cbdata.status = EFC_STATUS_INVALID;
  247. cbdata.ext_status = EFC_STATUS_INVALID;
  248. cbdata.els_rsp = els->io.rsp;
  249. if (els->els_retries_remaining) {
  250. els->els_retries_remaining--;
  251. rc = efc->tt.send_els(efc, &els->io);
  252. } else {
  253. rc = -EIO;
  254. }
  255. if (rc) {
  256. efc_log_err(efc, "ELS retries exhausted\n");
  257. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
  258. }
  259. }
  260. static int
  261. efc_els_acc_cb(void *arg, u32 length, int status, u32 ext_status)
  262. {
  263. struct efc_els_io_req *els;
  264. struct efc_node *node;
  265. struct efc *efc;
  266. struct efc_node_cb cbdata;
  267. els = arg;
  268. node = els->node;
  269. efc = node->efc;
  270. cbdata.status = status;
  271. cbdata.ext_status = ext_status;
  272. cbdata.header = NULL;
  273. cbdata.els_rsp = els->io.rsp;
  274. /* Post node event */
  275. switch (status) {
  276. case SLI4_FC_WCQE_STATUS_SUCCESS:
  277. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_OK, &cbdata);
  278. break;
  279. default: /* Other error */
  280. efc_log_warn(efc, "[%s] %-8s failed status x%x, ext x%x\n",
  281. node->display_name, els->display_name,
  282. status, ext_status);
  283. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_FAIL, &cbdata);
  284. break;
  285. }
  286. return 0;
  287. }
  288. static int
  289. efc_els_send_rsp(struct efc_els_io_req *els, u32 rsplen)
  290. {
  291. int rc = 0;
  292. struct efc_node_cb cbdata;
  293. struct efc_node *node = els->node;
  294. struct efc *efc = node->efc;
  295. /* increment ELS completion counter */
  296. node->els_cmpl_cnt++;
  297. els->io.io_type = EFC_DISC_IO_ELS_RESP;
  298. els->cb = efc_els_acc_cb;
  299. /* Prepare the IO request details */
  300. els->io.xmit_len = rsplen;
  301. els->io.rsp_len = els->io.rsp.size;
  302. els->io.rpi = node->rnode.indicator;
  303. els->io.vpi = node->nport->indicator;
  304. if (node->nport->fc_id != U32_MAX)
  305. els->io.s_id = node->nport->fc_id;
  306. else
  307. els->io.s_id = els->io.iparam.els.s_id;
  308. els->io.d_id = node->rnode.fc_id;
  309. if (node->attached)
  310. els->io.rpi_registered = true;
  311. rc = efc->tt.send_els(efc, &els->io);
  312. if (!rc)
  313. return rc;
  314. cbdata.status = EFC_STATUS_INVALID;
  315. cbdata.ext_status = EFC_STATUS_INVALID;
  316. cbdata.els_rsp = els->io.rsp;
  317. efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_FAIL, &cbdata);
  318. return rc;
  319. }
  320. int
  321. efc_send_plogi(struct efc_node *node)
  322. {
  323. struct efc_els_io_req *els;
  324. struct efc *efc = node->efc;
  325. struct fc_els_flogi *plogi;
  326. node_els_trace();
  327. els = efc_els_io_alloc(node, sizeof(*plogi));
  328. if (!els) {
  329. efc_log_err(efc, "IO alloc failed\n");
  330. return -EIO;
  331. }
  332. els->display_name = "plogi";
  333. /* Build PLOGI request */
  334. plogi = els->io.req.virt;
  335. memcpy(plogi, node->nport->service_params, sizeof(*plogi));
  336. plogi->fl_cmd = ELS_PLOGI;
  337. memset(plogi->_fl_resvd, 0, sizeof(plogi->_fl_resvd));
  338. return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
  339. }
  340. int
  341. efc_send_flogi(struct efc_node *node)
  342. {
  343. struct efc_els_io_req *els;
  344. struct efc *efc;
  345. struct fc_els_flogi *flogi;
  346. efc = node->efc;
  347. node_els_trace();
  348. els = efc_els_io_alloc(node, sizeof(*flogi));
  349. if (!els) {
  350. efc_log_err(efc, "IO alloc failed\n");
  351. return -EIO;
  352. }
  353. els->display_name = "flogi";
  354. /* Build FLOGI request */
  355. flogi = els->io.req.virt;
  356. memcpy(flogi, node->nport->service_params, sizeof(*flogi));
  357. flogi->fl_cmd = ELS_FLOGI;
  358. memset(flogi->_fl_resvd, 0, sizeof(flogi->_fl_resvd));
  359. return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
  360. }
  361. int
  362. efc_send_fdisc(struct efc_node *node)
  363. {
  364. struct efc_els_io_req *els;
  365. struct efc *efc;
  366. struct fc_els_flogi *fdisc;
  367. efc = node->efc;
  368. node_els_trace();
  369. els = efc_els_io_alloc(node, sizeof(*fdisc));
  370. if (!els) {
  371. efc_log_err(efc, "IO alloc failed\n");
  372. return -EIO;
  373. }
  374. els->display_name = "fdisc";
  375. /* Build FDISC request */
  376. fdisc = els->io.req.virt;
  377. memcpy(fdisc, node->nport->service_params, sizeof(*fdisc));
  378. fdisc->fl_cmd = ELS_FDISC;
  379. memset(fdisc->_fl_resvd, 0, sizeof(fdisc->_fl_resvd));
  380. return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
  381. }
  382. int
  383. efc_send_prli(struct efc_node *node)
  384. {
  385. struct efc *efc = node->efc;
  386. struct efc_els_io_req *els;
  387. struct {
  388. struct fc_els_prli prli;
  389. struct fc_els_spp spp;
  390. } *pp;
  391. node_els_trace();
  392. els = efc_els_io_alloc(node, sizeof(*pp));
  393. if (!els) {
  394. efc_log_err(efc, "IO alloc failed\n");
  395. return -EIO;
  396. }
  397. els->display_name = "prli";
  398. /* Build PRLI request */
  399. pp = els->io.req.virt;
  400. memset(pp, 0, sizeof(*pp));
  401. pp->prli.prli_cmd = ELS_PRLI;
  402. pp->prli.prli_spp_len = 16;
  403. pp->prli.prli_len = cpu_to_be16(sizeof(*pp));
  404. pp->spp.spp_type = FC_TYPE_FCP;
  405. pp->spp.spp_type_ext = 0;
  406. pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR;
  407. pp->spp.spp_params = cpu_to_be32(FCP_SPPF_RD_XRDY_DIS |
  408. (node->nport->enable_ini ?
  409. FCP_SPPF_INIT_FCN : 0) |
  410. (node->nport->enable_tgt ?
  411. FCP_SPPF_TARG_FCN : 0));
  412. return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
  413. }
  414. int
  415. efc_send_logo(struct efc_node *node)
  416. {
  417. struct efc *efc = node->efc;
  418. struct efc_els_io_req *els;
  419. struct fc_els_logo *logo;
  420. struct fc_els_flogi *sparams;
  421. node_els_trace();
  422. sparams = (struct fc_els_flogi *)node->nport->service_params;
  423. els = efc_els_io_alloc(node, sizeof(*logo));
  424. if (!els) {
  425. efc_log_err(efc, "IO alloc failed\n");
  426. return -EIO;
  427. }
  428. els->display_name = "logo";
  429. /* Build LOGO request */
  430. logo = els->io.req.virt;
  431. memset(logo, 0, sizeof(*logo));
  432. logo->fl_cmd = ELS_LOGO;
  433. hton24(logo->fl_n_port_id, node->rnode.nport->fc_id);
  434. logo->fl_n_port_wwn = sparams->fl_wwpn;
  435. return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
  436. }
  437. int
  438. efc_send_adisc(struct efc_node *node)
  439. {
  440. struct efc *efc = node->efc;
  441. struct efc_els_io_req *els;
  442. struct fc_els_adisc *adisc;
  443. struct fc_els_flogi *sparams;
  444. struct efc_nport *nport = node->nport;
  445. node_els_trace();
  446. sparams = (struct fc_els_flogi *)node->nport->service_params;
  447. els = efc_els_io_alloc(node, sizeof(*adisc));
  448. if (!els) {
  449. efc_log_err(efc, "IO alloc failed\n");
  450. return -EIO;
  451. }
  452. els->display_name = "adisc";
  453. /* Build ADISC request */
  454. adisc = els->io.req.virt;
  455. memset(adisc, 0, sizeof(*adisc));
  456. adisc->adisc_cmd = ELS_ADISC;
  457. hton24(adisc->adisc_hard_addr, nport->fc_id);
  458. adisc->adisc_wwpn = sparams->fl_wwpn;
  459. adisc->adisc_wwnn = sparams->fl_wwnn;
  460. hton24(adisc->adisc_port_id, node->rnode.nport->fc_id);
  461. return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
  462. }
  463. int
  464. efc_send_scr(struct efc_node *node)
  465. {
  466. struct efc_els_io_req *els;
  467. struct efc *efc = node->efc;
  468. struct fc_els_scr *req;
  469. node_els_trace();
  470. els = efc_els_io_alloc(node, sizeof(*req));
  471. if (!els) {
  472. efc_log_err(efc, "IO alloc failed\n");
  473. return -EIO;
  474. }
  475. els->display_name = "scr";
  476. req = els->io.req.virt;
  477. memset(req, 0, sizeof(*req));
  478. req->scr_cmd = ELS_SCR;
  479. req->scr_reg_func = ELS_SCRF_FULL;
  480. return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ);
  481. }
  482. int
  483. efc_send_ls_rjt(struct efc_node *node, u32 ox_id, u32 reason_code,
  484. u32 reason_code_expl, u32 vendor_unique)
  485. {
  486. struct efc *efc = node->efc;
  487. struct efc_els_io_req *els = NULL;
  488. struct fc_els_ls_rjt *rjt;
  489. els = efc_els_io_alloc(node, sizeof(*rjt));
  490. if (!els) {
  491. efc_log_err(efc, "els IO alloc failed\n");
  492. return -EIO;
  493. }
  494. node_els_trace();
  495. els->display_name = "ls_rjt";
  496. memset(&els->io.iparam, 0, sizeof(els->io.iparam));
  497. els->io.iparam.els.ox_id = ox_id;
  498. rjt = els->io.req.virt;
  499. memset(rjt, 0, sizeof(*rjt));
  500. rjt->er_cmd = ELS_LS_RJT;
  501. rjt->er_reason = reason_code;
  502. rjt->er_explan = reason_code_expl;
  503. return efc_els_send_rsp(els, sizeof(*rjt));
  504. }
  505. int
  506. efc_send_plogi_acc(struct efc_node *node, u32 ox_id)
  507. {
  508. struct efc *efc = node->efc;
  509. struct efc_els_io_req *els = NULL;
  510. struct fc_els_flogi *plogi;
  511. struct fc_els_flogi *req = (struct fc_els_flogi *)node->service_params;
  512. node_els_trace();
  513. els = efc_els_io_alloc(node, sizeof(*plogi));
  514. if (!els) {
  515. efc_log_err(efc, "els IO alloc failed\n");
  516. return -EIO;
  517. }
  518. els->display_name = "plogi_acc";
  519. memset(&els->io.iparam, 0, sizeof(els->io.iparam));
  520. els->io.iparam.els.ox_id = ox_id;
  521. plogi = els->io.req.virt;
  522. /* copy our port's service parameters to payload */
  523. memcpy(plogi, node->nport->service_params, sizeof(*plogi));
  524. plogi->fl_cmd = ELS_LS_ACC;
  525. memset(plogi->_fl_resvd, 0, sizeof(plogi->_fl_resvd));
  526. /* Set Application header support bit if requested */
  527. if (req->fl_csp.sp_features & cpu_to_be16(FC_SP_FT_BCAST))
  528. plogi->fl_csp.sp_features |= cpu_to_be16(FC_SP_FT_BCAST);
  529. return efc_els_send_rsp(els, sizeof(*plogi));
  530. }
  531. int
  532. efc_send_flogi_p2p_acc(struct efc_node *node, u32 ox_id, u32 s_id)
  533. {
  534. struct efc *efc = node->efc;
  535. struct efc_els_io_req *els = NULL;
  536. struct fc_els_flogi *flogi;
  537. node_els_trace();
  538. els = efc_els_io_alloc(node, sizeof(*flogi));
  539. if (!els) {
  540. efc_log_err(efc, "els IO alloc failed\n");
  541. return -EIO;
  542. }
  543. els->display_name = "flogi_p2p_acc";
  544. memset(&els->io.iparam, 0, sizeof(els->io.iparam));
  545. els->io.iparam.els.ox_id = ox_id;
  546. els->io.iparam.els.s_id = s_id;
  547. flogi = els->io.req.virt;
  548. /* copy our port's service parameters to payload */
  549. memcpy(flogi, node->nport->service_params, sizeof(*flogi));
  550. flogi->fl_cmd = ELS_LS_ACC;
  551. memset(flogi->_fl_resvd, 0, sizeof(flogi->_fl_resvd));
  552. memset(flogi->fl_cssp, 0, sizeof(flogi->fl_cssp));
  553. return efc_els_send_rsp(els, sizeof(*flogi));
  554. }
  555. int
  556. efc_send_prli_acc(struct efc_node *node, u32 ox_id)
  557. {
  558. struct efc *efc = node->efc;
  559. struct efc_els_io_req *els = NULL;
  560. struct {
  561. struct fc_els_prli prli;
  562. struct fc_els_spp spp;
  563. } *pp;
  564. node_els_trace();
  565. els = efc_els_io_alloc(node, sizeof(*pp));
  566. if (!els) {
  567. efc_log_err(efc, "els IO alloc failed\n");
  568. return -EIO;
  569. }
  570. els->display_name = "prli_acc";
  571. memset(&els->io.iparam, 0, sizeof(els->io.iparam));
  572. els->io.iparam.els.ox_id = ox_id;
  573. pp = els->io.req.virt;
  574. memset(pp, 0, sizeof(*pp));
  575. pp->prli.prli_cmd = ELS_LS_ACC;
  576. pp->prli.prli_spp_len = 0x10;
  577. pp->prli.prli_len = cpu_to_be16(sizeof(*pp));
  578. pp->spp.spp_type = FC_TYPE_FCP;
  579. pp->spp.spp_type_ext = 0;
  580. pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR | FC_SPP_RESP_ACK;
  581. pp->spp.spp_params = cpu_to_be32(FCP_SPPF_RD_XRDY_DIS |
  582. (node->nport->enable_ini ?
  583. FCP_SPPF_INIT_FCN : 0) |
  584. (node->nport->enable_tgt ?
  585. FCP_SPPF_TARG_FCN : 0));
  586. return efc_els_send_rsp(els, sizeof(*pp));
  587. }
  588. int
  589. efc_send_prlo_acc(struct efc_node *node, u32 ox_id)
  590. {
  591. struct efc *efc = node->efc;
  592. struct efc_els_io_req *els = NULL;
  593. struct {
  594. struct fc_els_prlo prlo;
  595. struct fc_els_spp spp;
  596. } *pp;
  597. node_els_trace();
  598. els = efc_els_io_alloc(node, sizeof(*pp));
  599. if (!els) {
  600. efc_log_err(efc, "els IO alloc failed\n");
  601. return -EIO;
  602. }
  603. els->display_name = "prlo_acc";
  604. memset(&els->io.iparam, 0, sizeof(els->io.iparam));
  605. els->io.iparam.els.ox_id = ox_id;
  606. pp = els->io.req.virt;
  607. memset(pp, 0, sizeof(*pp));
  608. pp->prlo.prlo_cmd = ELS_LS_ACC;
  609. pp->prlo.prlo_obs = 0x10;
  610. pp->prlo.prlo_len = cpu_to_be16(sizeof(*pp));
  611. pp->spp.spp_type = FC_TYPE_FCP;
  612. pp->spp.spp_type_ext = 0;
  613. pp->spp.spp_flags = FC_SPP_RESP_ACK;
  614. return efc_els_send_rsp(els, sizeof(*pp));
  615. }
  616. int
  617. efc_send_ls_acc(struct efc_node *node, u32 ox_id)
  618. {
  619. struct efc *efc = node->efc;
  620. struct efc_els_io_req *els = NULL;
  621. struct fc_els_ls_acc *acc;
  622. node_els_trace();
  623. els = efc_els_io_alloc(node, sizeof(*acc));
  624. if (!els) {
  625. efc_log_err(efc, "els IO alloc failed\n");
  626. return -EIO;
  627. }
  628. els->display_name = "ls_acc";
  629. memset(&els->io.iparam, 0, sizeof(els->io.iparam));
  630. els->io.iparam.els.ox_id = ox_id;
  631. acc = els->io.req.virt;
  632. memset(acc, 0, sizeof(*acc));
  633. acc->la_cmd = ELS_LS_ACC;
  634. return efc_els_send_rsp(els, sizeof(*acc));
  635. }
  636. int
  637. efc_send_logo_acc(struct efc_node *node, u32 ox_id)
  638. {
  639. struct efc_els_io_req *els = NULL;
  640. struct efc *efc = node->efc;
  641. struct fc_els_ls_acc *logo;
  642. node_els_trace();
  643. els = efc_els_io_alloc(node, sizeof(*logo));
  644. if (!els) {
  645. efc_log_err(efc, "els IO alloc failed\n");
  646. return -EIO;
  647. }
  648. els->display_name = "logo_acc";
  649. memset(&els->io.iparam, 0, sizeof(els->io.iparam));
  650. els->io.iparam.els.ox_id = ox_id;
  651. logo = els->io.req.virt;
  652. memset(logo, 0, sizeof(*logo));
  653. logo->la_cmd = ELS_LS_ACC;
  654. return efc_els_send_rsp(els, sizeof(*logo));
  655. }
  656. int
  657. efc_send_adisc_acc(struct efc_node *node, u32 ox_id)
  658. {
  659. struct efc *efc = node->efc;
  660. struct efc_els_io_req *els = NULL;
  661. struct fc_els_adisc *adisc;
  662. struct fc_els_flogi *sparams;
  663. node_els_trace();
  664. els = efc_els_io_alloc(node, sizeof(*adisc));
  665. if (!els) {
  666. efc_log_err(efc, "els IO alloc failed\n");
  667. return -EIO;
  668. }
  669. els->display_name = "adisc_acc";
  670. /* Go ahead and send the ELS_ACC */
  671. memset(&els->io.iparam, 0, sizeof(els->io.iparam));
  672. els->io.iparam.els.ox_id = ox_id;
  673. sparams = (struct fc_els_flogi *)node->nport->service_params;
  674. adisc = els->io.req.virt;
  675. memset(adisc, 0, sizeof(*adisc));
  676. adisc->adisc_cmd = ELS_LS_ACC;
  677. adisc->adisc_wwpn = sparams->fl_wwpn;
  678. adisc->adisc_wwnn = sparams->fl_wwnn;
  679. hton24(adisc->adisc_port_id, node->rnode.nport->fc_id);
  680. return efc_els_send_rsp(els, sizeof(*adisc));
  681. }
  682. static inline void
  683. fcct_build_req_header(struct fc_ct_hdr *hdr, u16 cmd, u16 max_size)
  684. {
  685. hdr->ct_rev = FC_CT_REV;
  686. hdr->ct_fs_type = FC_FST_DIR;
  687. hdr->ct_fs_subtype = FC_NS_SUBTYPE;
  688. hdr->ct_options = 0;
  689. hdr->ct_cmd = cpu_to_be16(cmd);
  690. /* words */
  691. hdr->ct_mr_size = cpu_to_be16(max_size / (sizeof(u32)));
  692. hdr->ct_reason = 0;
  693. hdr->ct_explan = 0;
  694. hdr->ct_vendor = 0;
  695. }
  696. int
  697. efc_ns_send_rftid(struct efc_node *node)
  698. {
  699. struct efc *efc = node->efc;
  700. struct efc_els_io_req *els;
  701. struct {
  702. struct fc_ct_hdr hdr;
  703. struct fc_ns_rft_id rftid;
  704. } *ct;
  705. node_els_trace();
  706. els = efc_els_io_alloc(node, sizeof(*ct));
  707. if (!els) {
  708. efc_log_err(efc, "IO alloc failed\n");
  709. return -EIO;
  710. }
  711. els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ;
  712. els->io.iparam.ct.type = FC_TYPE_CT;
  713. els->io.iparam.ct.df_ctl = 0;
  714. els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT;
  715. els->display_name = "rftid";
  716. ct = els->io.req.virt;
  717. memset(ct, 0, sizeof(*ct));
  718. fcct_build_req_header(&ct->hdr, FC_NS_RFT_ID,
  719. sizeof(struct fc_ns_rft_id));
  720. hton24(ct->rftid.fr_fid.fp_fid, node->rnode.nport->fc_id);
  721. ct->rftid.fr_fts.ff_type_map[FC_TYPE_FCP / FC_NS_BPW] =
  722. cpu_to_be32(1 << (FC_TYPE_FCP % FC_NS_BPW));
  723. return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ);
  724. }
  725. int
  726. efc_ns_send_rffid(struct efc_node *node)
  727. {
  728. struct efc *efc = node->efc;
  729. struct efc_els_io_req *els;
  730. struct {
  731. struct fc_ct_hdr hdr;
  732. struct fc_ns_rff_id rffid;
  733. } *ct;
  734. node_els_trace();
  735. els = efc_els_io_alloc(node, sizeof(*ct));
  736. if (!els) {
  737. efc_log_err(efc, "IO alloc failed\n");
  738. return -EIO;
  739. }
  740. els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ;
  741. els->io.iparam.ct.type = FC_TYPE_CT;
  742. els->io.iparam.ct.df_ctl = 0;
  743. els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT;
  744. els->display_name = "rffid";
  745. ct = els->io.req.virt;
  746. memset(ct, 0, sizeof(*ct));
  747. fcct_build_req_header(&ct->hdr, FC_NS_RFF_ID,
  748. sizeof(struct fc_ns_rff_id));
  749. hton24(ct->rffid.fr_fid.fp_fid, node->rnode.nport->fc_id);
  750. if (node->nport->enable_ini)
  751. ct->rffid.fr_feat |= FCP_FEAT_INIT;
  752. if (node->nport->enable_tgt)
  753. ct->rffid.fr_feat |= FCP_FEAT_TARG;
  754. ct->rffid.fr_type = FC_TYPE_FCP;
  755. return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ);
  756. }
  757. int
  758. efc_ns_send_gidpt(struct efc_node *node)
  759. {
  760. struct efc_els_io_req *els = NULL;
  761. struct efc *efc = node->efc;
  762. struct {
  763. struct fc_ct_hdr hdr;
  764. struct fc_ns_gid_pt gidpt;
  765. } *ct;
  766. node_els_trace();
  767. els = efc_els_io_alloc_size(node, sizeof(*ct), EFC_ELS_GID_PT_RSP_LEN);
  768. if (!els) {
  769. efc_log_err(efc, "IO alloc failed\n");
  770. return -EIO;
  771. }
  772. els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ;
  773. els->io.iparam.ct.type = FC_TYPE_CT;
  774. els->io.iparam.ct.df_ctl = 0;
  775. els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT;
  776. els->display_name = "gidpt";
  777. ct = els->io.req.virt;
  778. memset(ct, 0, sizeof(*ct));
  779. fcct_build_req_header(&ct->hdr, FC_NS_GID_PT,
  780. sizeof(struct fc_ns_gid_pt));
  781. ct->gidpt.fn_pt_type = FC_TYPE_FCP;
  782. return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ);
  783. }
  784. void
  785. efc_els_io_cleanup(struct efc_els_io_req *els, int evt, void *arg)
  786. {
  787. /* don't want further events that could come; e.g. abort requests
  788. * from the node state machine; thus, disable state machine
  789. */
  790. els->els_req_free = true;
  791. efc_node_post_els_resp(els->node, evt, arg);
  792. efc_els_io_free(els);
  793. }
  794. static int
  795. efc_ct_acc_cb(void *arg, u32 length, int status, u32 ext_status)
  796. {
  797. struct efc_els_io_req *els = arg;
  798. efc_els_io_free(els);
  799. return 0;
  800. }
  801. int
  802. efc_send_ct_rsp(struct efc *efc, struct efc_node *node, u16 ox_id,
  803. struct fc_ct_hdr *ct_hdr, u32 cmd_rsp_code,
  804. u32 reason_code, u32 reason_code_explanation)
  805. {
  806. struct efc_els_io_req *els = NULL;
  807. struct fc_ct_hdr *rsp = NULL;
  808. els = efc_els_io_alloc(node, 256);
  809. if (!els) {
  810. efc_log_err(efc, "IO alloc failed\n");
  811. return -EIO;
  812. }
  813. rsp = els->io.rsp.virt;
  814. *rsp = *ct_hdr;
  815. fcct_build_req_header(rsp, cmd_rsp_code, 0);
  816. rsp->ct_reason = reason_code;
  817. rsp->ct_explan = reason_code_explanation;
  818. els->display_name = "ct_rsp";
  819. els->cb = efc_ct_acc_cb;
  820. /* Prepare the IO request details */
  821. els->io.io_type = EFC_DISC_IO_CT_RESP;
  822. els->io.xmit_len = sizeof(*rsp);
  823. els->io.rpi = node->rnode.indicator;
  824. els->io.d_id = node->rnode.fc_id;
  825. memset(&els->io.iparam, 0, sizeof(els->io.iparam));
  826. els->io.iparam.ct.ox_id = ox_id;
  827. els->io.iparam.ct.r_ctl = 3;
  828. els->io.iparam.ct.type = FC_TYPE_CT;
  829. els->io.iparam.ct.df_ctl = 0;
  830. els->io.iparam.ct.timeout = 5;
  831. if (efc->tt.send_els(efc, &els->io)) {
  832. efc_els_io_free(els);
  833. return -EIO;
  834. }
  835. return 0;
  836. }
  837. int
  838. efc_send_bls_acc(struct efc_node *node, struct fc_frame_header *hdr)
  839. {
  840. struct sli_bls_params bls;
  841. struct fc_ba_acc *acc;
  842. struct efc *efc = node->efc;
  843. memset(&bls, 0, sizeof(bls));
  844. bls.ox_id = be16_to_cpu(hdr->fh_ox_id);
  845. bls.rx_id = be16_to_cpu(hdr->fh_rx_id);
  846. bls.s_id = ntoh24(hdr->fh_d_id);
  847. bls.d_id = node->rnode.fc_id;
  848. bls.rpi = node->rnode.indicator;
  849. bls.vpi = node->nport->indicator;
  850. acc = (void *)bls.payload;
  851. acc->ba_ox_id = cpu_to_be16(bls.ox_id);
  852. acc->ba_rx_id = cpu_to_be16(bls.rx_id);
  853. acc->ba_high_seq_cnt = cpu_to_be16(U16_MAX);
  854. return efc->tt.send_bls(efc, FC_RCTL_BA_ACC, &bls);
  855. }