bfa_fcbuild.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /*
  18. * fcbuild.c - FC link service frame building and parsing routines
  19. */
  20. #include "bfad_drv.h"
  21. #include "bfa_fcbuild.h"
  22. /*
  23. * static build functions
  24. */
  25. static void fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  26. __be16 ox_id);
  27. static void fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  28. __be16 ox_id);
  29. static struct fchs_s fc_els_req_tmpl;
  30. static struct fchs_s fc_els_rsp_tmpl;
  31. static struct fchs_s fc_bls_req_tmpl;
  32. static struct fchs_s fc_bls_rsp_tmpl;
  33. static struct fc_ba_acc_s ba_acc_tmpl;
  34. static struct fc_logi_s plogi_tmpl;
  35. static struct fc_prli_s prli_tmpl;
  36. static struct fc_rrq_s rrq_tmpl;
  37. static struct fchs_s fcp_fchs_tmpl;
  38. void
  39. fcbuild_init(void)
  40. {
  41. /*
  42. * fc_els_req_tmpl
  43. */
  44. fc_els_req_tmpl.routing = FC_RTG_EXT_LINK;
  45. fc_els_req_tmpl.cat_info = FC_CAT_LD_REQUEST;
  46. fc_els_req_tmpl.type = FC_TYPE_ELS;
  47. fc_els_req_tmpl.f_ctl =
  48. bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
  49. FCTL_SI_XFER);
  50. fc_els_req_tmpl.rx_id = FC_RXID_ANY;
  51. /*
  52. * fc_els_rsp_tmpl
  53. */
  54. fc_els_rsp_tmpl.routing = FC_RTG_EXT_LINK;
  55. fc_els_rsp_tmpl.cat_info = FC_CAT_LD_REPLY;
  56. fc_els_rsp_tmpl.type = FC_TYPE_ELS;
  57. fc_els_rsp_tmpl.f_ctl =
  58. bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
  59. FCTL_END_SEQ | FCTL_SI_XFER);
  60. fc_els_rsp_tmpl.rx_id = FC_RXID_ANY;
  61. /*
  62. * fc_bls_req_tmpl
  63. */
  64. fc_bls_req_tmpl.routing = FC_RTG_BASIC_LINK;
  65. fc_bls_req_tmpl.type = FC_TYPE_BLS;
  66. fc_bls_req_tmpl.f_ctl = bfa_hton3b(FCTL_END_SEQ | FCTL_SI_XFER);
  67. fc_bls_req_tmpl.rx_id = FC_RXID_ANY;
  68. /*
  69. * fc_bls_rsp_tmpl
  70. */
  71. fc_bls_rsp_tmpl.routing = FC_RTG_BASIC_LINK;
  72. fc_bls_rsp_tmpl.cat_info = FC_CAT_BA_ACC;
  73. fc_bls_rsp_tmpl.type = FC_TYPE_BLS;
  74. fc_bls_rsp_tmpl.f_ctl =
  75. bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
  76. FCTL_END_SEQ | FCTL_SI_XFER);
  77. fc_bls_rsp_tmpl.rx_id = FC_RXID_ANY;
  78. /*
  79. * ba_acc_tmpl
  80. */
  81. ba_acc_tmpl.seq_id_valid = 0;
  82. ba_acc_tmpl.low_seq_cnt = 0;
  83. ba_acc_tmpl.high_seq_cnt = 0xFFFF;
  84. /*
  85. * plogi_tmpl
  86. */
  87. plogi_tmpl.csp.verhi = FC_PH_VER_PH_3;
  88. plogi_tmpl.csp.verlo = FC_PH_VER_4_3;
  89. plogi_tmpl.csp.ciro = 0x1;
  90. plogi_tmpl.csp.cisc = 0x0;
  91. plogi_tmpl.csp.altbbcred = 0x0;
  92. plogi_tmpl.csp.conseq = cpu_to_be16(0x00FF);
  93. plogi_tmpl.csp.ro_bitmap = cpu_to_be16(0x0002);
  94. plogi_tmpl.csp.e_d_tov = cpu_to_be32(2000);
  95. plogi_tmpl.class3.class_valid = 1;
  96. plogi_tmpl.class3.sequential = 1;
  97. plogi_tmpl.class3.conseq = 0xFF;
  98. plogi_tmpl.class3.ospx = 1;
  99. /*
  100. * prli_tmpl
  101. */
  102. prli_tmpl.command = FC_ELS_PRLI;
  103. prli_tmpl.pglen = 0x10;
  104. prli_tmpl.pagebytes = cpu_to_be16(0x0014);
  105. prli_tmpl.parampage.type = FC_TYPE_FCP;
  106. prli_tmpl.parampage.imagepair = 1;
  107. prli_tmpl.parampage.servparams.rxrdisab = 1;
  108. /*
  109. * rrq_tmpl
  110. */
  111. rrq_tmpl.els_cmd.els_code = FC_ELS_RRQ;
  112. /*
  113. * fcp_struct fchs_s mpl
  114. */
  115. fcp_fchs_tmpl.routing = FC_RTG_FC4_DEV_DATA;
  116. fcp_fchs_tmpl.cat_info = FC_CAT_UNSOLICIT_CMD;
  117. fcp_fchs_tmpl.type = FC_TYPE_FCP;
  118. fcp_fchs_tmpl.f_ctl =
  119. bfa_hton3b(FCTL_FS_EXCH | FCTL_END_SEQ | FCTL_SI_XFER);
  120. fcp_fchs_tmpl.seq_id = 1;
  121. fcp_fchs_tmpl.rx_id = FC_RXID_ANY;
  122. }
  123. static void
  124. fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id)
  125. {
  126. memset(fchs, 0, sizeof(struct fchs_s));
  127. fchs->routing = FC_RTG_FC4_DEV_DATA;
  128. fchs->cat_info = FC_CAT_UNSOLICIT_CTRL;
  129. fchs->type = FC_TYPE_SERVICES;
  130. fchs->f_ctl =
  131. bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
  132. FCTL_SI_XFER);
  133. fchs->rx_id = FC_RXID_ANY;
  134. fchs->d_id = (d_id);
  135. fchs->s_id = (s_id);
  136. fchs->ox_id = cpu_to_be16(ox_id);
  137. /*
  138. * @todo no need to set ox_id for request
  139. * no need to set rx_id for response
  140. */
  141. }
  142. static void
  143. fc_gsresp_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
  144. {
  145. memset(fchs, 0, sizeof(struct fchs_s));
  146. fchs->routing = FC_RTG_FC4_DEV_DATA;
  147. fchs->cat_info = FC_CAT_SOLICIT_CTRL;
  148. fchs->type = FC_TYPE_SERVICES;
  149. fchs->f_ctl =
  150. bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
  151. FCTL_END_SEQ | FCTL_SI_XFER);
  152. fchs->d_id = d_id;
  153. fchs->s_id = s_id;
  154. fchs->ox_id = ox_id;
  155. }
  156. void
  157. fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
  158. {
  159. memcpy(fchs, &fc_els_req_tmpl, sizeof(struct fchs_s));
  160. fchs->d_id = (d_id);
  161. fchs->s_id = (s_id);
  162. fchs->ox_id = cpu_to_be16(ox_id);
  163. }
  164. static void
  165. fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
  166. {
  167. memcpy(fchs, &fc_els_rsp_tmpl, sizeof(struct fchs_s));
  168. fchs->d_id = d_id;
  169. fchs->s_id = s_id;
  170. fchs->ox_id = ox_id;
  171. }
  172. enum fc_parse_status
  173. fc_els_rsp_parse(struct fchs_s *fchs, int len)
  174. {
  175. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  176. struct fc_ls_rjt_s *ls_rjt = (struct fc_ls_rjt_s *) els_cmd;
  177. len = len;
  178. switch (els_cmd->els_code) {
  179. case FC_ELS_LS_RJT:
  180. if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
  181. return FC_PARSE_BUSY;
  182. else
  183. return FC_PARSE_FAILURE;
  184. case FC_ELS_ACC:
  185. return FC_PARSE_OK;
  186. }
  187. return FC_PARSE_OK;
  188. }
  189. static void
  190. fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
  191. {
  192. memcpy(fchs, &fc_bls_rsp_tmpl, sizeof(struct fchs_s));
  193. fchs->d_id = d_id;
  194. fchs->s_id = s_id;
  195. fchs->ox_id = ox_id;
  196. }
  197. static u16
  198. fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
  199. __be16 ox_id, wwn_t port_name, wwn_t node_name,
  200. u16 pdu_size, u16 bb_cr, u8 els_code)
  201. {
  202. struct fc_logi_s *plogi = (struct fc_logi_s *) (pld);
  203. memcpy(plogi, &plogi_tmpl, sizeof(struct fc_logi_s));
  204. /* For FC AL bb_cr is 0 and altbbcred is 1 */
  205. if (!bb_cr)
  206. plogi->csp.altbbcred = 1;
  207. plogi->els_cmd.els_code = els_code;
  208. if (els_code == FC_ELS_PLOGI)
  209. fc_els_req_build(fchs, d_id, s_id, ox_id);
  210. else
  211. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  212. plogi->csp.rxsz = plogi->class3.rxsz = cpu_to_be16(pdu_size);
  213. plogi->csp.bbcred = cpu_to_be16(bb_cr);
  214. memcpy(&plogi->port_name, &port_name, sizeof(wwn_t));
  215. memcpy(&plogi->node_name, &node_name, sizeof(wwn_t));
  216. return sizeof(struct fc_logi_s);
  217. }
  218. u16
  219. fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
  220. u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size,
  221. u8 set_npiv, u8 set_auth, u16 local_bb_credits)
  222. {
  223. u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
  224. __be32 *vvl_info;
  225. memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
  226. flogi->els_cmd.els_code = FC_ELS_FLOGI;
  227. fc_els_req_build(fchs, d_id, s_id, ox_id);
  228. flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
  229. flogi->port_name = port_name;
  230. flogi->node_name = node_name;
  231. /*
  232. * Set the NPIV Capability Bit ( word 1, bit 31) of Common
  233. * Service Parameters.
  234. */
  235. flogi->csp.ciro = set_npiv;
  236. /* set AUTH capability */
  237. flogi->csp.security = set_auth;
  238. flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
  239. /* Set brcd token in VVL */
  240. vvl_info = (u32 *)&flogi->vvl[0];
  241. /* set the flag to indicate the presence of VVL */
  242. flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */
  243. vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD);
  244. return sizeof(struct fc_logi_s);
  245. }
  246. u16
  247. fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
  248. __be16 ox_id, wwn_t port_name, wwn_t node_name,
  249. u16 pdu_size, u16 local_bb_credits, u8 bb_scn)
  250. {
  251. u32 d_id = 0;
  252. u16 bbscn_rxsz = (bb_scn << 12) | pdu_size;
  253. memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
  254. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  255. flogi->els_cmd.els_code = FC_ELS_ACC;
  256. flogi->class3.rxsz = cpu_to_be16(pdu_size);
  257. flogi->csp.rxsz = cpu_to_be16(bbscn_rxsz); /* bb_scn/rxsz */
  258. flogi->port_name = port_name;
  259. flogi->node_name = node_name;
  260. flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
  261. return sizeof(struct fc_logi_s);
  262. }
  263. u16
  264. fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
  265. u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size)
  266. {
  267. u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
  268. memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
  269. flogi->els_cmd.els_code = FC_ELS_FDISC;
  270. fc_els_req_build(fchs, d_id, s_id, ox_id);
  271. flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
  272. flogi->port_name = port_name;
  273. flogi->node_name = node_name;
  274. return sizeof(struct fc_logi_s);
  275. }
  276. u16
  277. fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
  278. u16 ox_id, wwn_t port_name, wwn_t node_name,
  279. u16 pdu_size, u16 bb_cr)
  280. {
  281. return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
  282. node_name, pdu_size, bb_cr, FC_ELS_PLOGI);
  283. }
  284. u16
  285. fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
  286. u16 ox_id, wwn_t port_name, wwn_t node_name,
  287. u16 pdu_size, u16 bb_cr)
  288. {
  289. return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
  290. node_name, pdu_size, bb_cr, FC_ELS_ACC);
  291. }
  292. enum fc_parse_status
  293. fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
  294. {
  295. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  296. struct fc_logi_s *plogi;
  297. struct fc_ls_rjt_s *ls_rjt;
  298. switch (els_cmd->els_code) {
  299. case FC_ELS_LS_RJT:
  300. ls_rjt = (struct fc_ls_rjt_s *) (fchs + 1);
  301. if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
  302. return FC_PARSE_BUSY;
  303. else
  304. return FC_PARSE_FAILURE;
  305. case FC_ELS_ACC:
  306. plogi = (struct fc_logi_s *) (fchs + 1);
  307. if (len < sizeof(struct fc_logi_s))
  308. return FC_PARSE_FAILURE;
  309. if (!wwn_is_equal(plogi->port_name, port_name))
  310. return FC_PARSE_FAILURE;
  311. if (!plogi->class3.class_valid)
  312. return FC_PARSE_FAILURE;
  313. if (be16_to_cpu(plogi->class3.rxsz) < (FC_MIN_PDUSZ))
  314. return FC_PARSE_FAILURE;
  315. return FC_PARSE_OK;
  316. default:
  317. return FC_PARSE_FAILURE;
  318. }
  319. }
  320. enum fc_parse_status
  321. fc_plogi_parse(struct fchs_s *fchs)
  322. {
  323. struct fc_logi_s *plogi = (struct fc_logi_s *) (fchs + 1);
  324. if (plogi->class3.class_valid != 1)
  325. return FC_PARSE_FAILURE;
  326. if ((be16_to_cpu(plogi->class3.rxsz) < FC_MIN_PDUSZ)
  327. || (be16_to_cpu(plogi->class3.rxsz) > FC_MAX_PDUSZ)
  328. || (plogi->class3.rxsz == 0))
  329. return FC_PARSE_FAILURE;
  330. return FC_PARSE_OK;
  331. }
  332. u16
  333. fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
  334. u16 ox_id)
  335. {
  336. struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
  337. fc_els_req_build(fchs, d_id, s_id, ox_id);
  338. memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
  339. prli->command = FC_ELS_PRLI;
  340. prli->parampage.servparams.initiator = 1;
  341. prli->parampage.servparams.retry = 1;
  342. prli->parampage.servparams.rec_support = 1;
  343. prli->parampage.servparams.task_retry_id = 0;
  344. prli->parampage.servparams.confirm = 1;
  345. return sizeof(struct fc_prli_s);
  346. }
  347. u16
  348. fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
  349. __be16 ox_id, enum bfa_lport_role role)
  350. {
  351. struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
  352. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  353. memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
  354. prli->command = FC_ELS_ACC;
  355. prli->parampage.servparams.initiator = 1;
  356. prli->parampage.rspcode = FC_PRLI_ACC_XQTD;
  357. return sizeof(struct fc_prli_s);
  358. }
  359. enum fc_parse_status
  360. fc_prli_rsp_parse(struct fc_prli_s *prli, int len)
  361. {
  362. if (len < sizeof(struct fc_prli_s))
  363. return FC_PARSE_FAILURE;
  364. if (prli->command != FC_ELS_ACC)
  365. return FC_PARSE_FAILURE;
  366. if ((prli->parampage.rspcode != FC_PRLI_ACC_XQTD)
  367. && (prli->parampage.rspcode != FC_PRLI_ACC_PREDEF_IMG))
  368. return FC_PARSE_FAILURE;
  369. if (prli->parampage.servparams.target != 1)
  370. return FC_PARSE_FAILURE;
  371. return FC_PARSE_OK;
  372. }
  373. enum fc_parse_status
  374. fc_prli_parse(struct fc_prli_s *prli)
  375. {
  376. if (prli->parampage.type != FC_TYPE_FCP)
  377. return FC_PARSE_FAILURE;
  378. if (!prli->parampage.imagepair)
  379. return FC_PARSE_FAILURE;
  380. if (!prli->parampage.servparams.initiator)
  381. return FC_PARSE_FAILURE;
  382. return FC_PARSE_OK;
  383. }
  384. u16
  385. fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id, u32 s_id,
  386. u16 ox_id, wwn_t port_name)
  387. {
  388. fc_els_req_build(fchs, d_id, s_id, ox_id);
  389. memset(logo, '\0', sizeof(struct fc_logo_s));
  390. logo->els_cmd.els_code = FC_ELS_LOGO;
  391. logo->nport_id = (s_id);
  392. logo->orig_port_name = port_name;
  393. return sizeof(struct fc_logo_s);
  394. }
  395. static u16
  396. fc_adisc_x_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
  397. u32 s_id, __be16 ox_id, wwn_t port_name,
  398. wwn_t node_name, u8 els_code)
  399. {
  400. memset(adisc, '\0', sizeof(struct fc_adisc_s));
  401. adisc->els_cmd.els_code = els_code;
  402. if (els_code == FC_ELS_ADISC)
  403. fc_els_req_build(fchs, d_id, s_id, ox_id);
  404. else
  405. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  406. adisc->orig_HA = 0;
  407. adisc->orig_port_name = port_name;
  408. adisc->orig_node_name = node_name;
  409. adisc->nport_id = (s_id);
  410. return sizeof(struct fc_adisc_s);
  411. }
  412. u16
  413. fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
  414. u32 s_id, __be16 ox_id, wwn_t port_name, wwn_t node_name)
  415. {
  416. return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
  417. node_name, FC_ELS_ADISC);
  418. }
  419. u16
  420. fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
  421. u32 s_id, __be16 ox_id, wwn_t port_name,
  422. wwn_t node_name)
  423. {
  424. return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
  425. node_name, FC_ELS_ACC);
  426. }
  427. enum fc_parse_status
  428. fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len, wwn_t port_name,
  429. wwn_t node_name)
  430. {
  431. if (len < sizeof(struct fc_adisc_s))
  432. return FC_PARSE_FAILURE;
  433. if (adisc->els_cmd.els_code != FC_ELS_ACC)
  434. return FC_PARSE_FAILURE;
  435. if (!wwn_is_equal(adisc->orig_port_name, port_name))
  436. return FC_PARSE_FAILURE;
  437. return FC_PARSE_OK;
  438. }
  439. enum fc_parse_status
  440. fc_adisc_parse(struct fchs_s *fchs, void *pld, u32 host_dap, wwn_t node_name,
  441. wwn_t port_name)
  442. {
  443. struct fc_adisc_s *adisc = (struct fc_adisc_s *) pld;
  444. if (adisc->els_cmd.els_code != FC_ELS_ACC)
  445. return FC_PARSE_FAILURE;
  446. if ((adisc->nport_id == (host_dap))
  447. && wwn_is_equal(adisc->orig_port_name, port_name)
  448. && wwn_is_equal(adisc->orig_node_name, node_name))
  449. return FC_PARSE_OK;
  450. return FC_PARSE_FAILURE;
  451. }
  452. enum fc_parse_status
  453. fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name)
  454. {
  455. struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
  456. if (pdisc->class3.class_valid != 1)
  457. return FC_PARSE_FAILURE;
  458. if ((be16_to_cpu(pdisc->class3.rxsz) <
  459. (FC_MIN_PDUSZ - sizeof(struct fchs_s)))
  460. || (pdisc->class3.rxsz == 0))
  461. return FC_PARSE_FAILURE;
  462. if (!wwn_is_equal(pdisc->port_name, port_name))
  463. return FC_PARSE_FAILURE;
  464. if (!wwn_is_equal(pdisc->node_name, node_name))
  465. return FC_PARSE_FAILURE;
  466. return FC_PARSE_OK;
  467. }
  468. u16
  469. fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
  470. {
  471. memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s));
  472. fchs->cat_info = FC_CAT_ABTS;
  473. fchs->d_id = (d_id);
  474. fchs->s_id = (s_id);
  475. fchs->ox_id = cpu_to_be16(ox_id);
  476. return sizeof(struct fchs_s);
  477. }
  478. enum fc_parse_status
  479. fc_abts_rsp_parse(struct fchs_s *fchs, int len)
  480. {
  481. if ((fchs->cat_info == FC_CAT_BA_ACC)
  482. || (fchs->cat_info == FC_CAT_BA_RJT))
  483. return FC_PARSE_OK;
  484. return FC_PARSE_FAILURE;
  485. }
  486. u16
  487. fc_rrq_build(struct fchs_s *fchs, struct fc_rrq_s *rrq, u32 d_id, u32 s_id,
  488. u16 ox_id, u16 rrq_oxid)
  489. {
  490. fc_els_req_build(fchs, d_id, s_id, ox_id);
  491. /*
  492. * build rrq payload
  493. */
  494. memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s));
  495. rrq->s_id = (s_id);
  496. rrq->ox_id = cpu_to_be16(rrq_oxid);
  497. rrq->rx_id = FC_RXID_ANY;
  498. return sizeof(struct fc_rrq_s);
  499. }
  500. u16
  501. fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
  502. __be16 ox_id)
  503. {
  504. struct fc_els_cmd_s *acc = pld;
  505. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  506. memset(acc, 0, sizeof(struct fc_els_cmd_s));
  507. acc->els_code = FC_ELS_ACC;
  508. return sizeof(struct fc_els_cmd_s);
  509. }
  510. u16
  511. fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt, u32 d_id,
  512. u32 s_id, __be16 ox_id, u8 reason_code,
  513. u8 reason_code_expl)
  514. {
  515. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  516. memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s));
  517. ls_rjt->els_cmd.els_code = FC_ELS_LS_RJT;
  518. ls_rjt->reason_code = reason_code;
  519. ls_rjt->reason_code_expl = reason_code_expl;
  520. ls_rjt->vendor_unique = 0x00;
  521. return sizeof(struct fc_ls_rjt_s);
  522. }
  523. u16
  524. fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
  525. u32 s_id, __be16 ox_id, u16 rx_id)
  526. {
  527. fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
  528. memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s));
  529. fchs->rx_id = rx_id;
  530. ba_acc->ox_id = fchs->ox_id;
  531. ba_acc->rx_id = fchs->rx_id;
  532. return sizeof(struct fc_ba_acc_s);
  533. }
  534. u16
  535. fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd, u32 d_id,
  536. u32 s_id, __be16 ox_id)
  537. {
  538. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  539. memset(els_cmd, 0, sizeof(struct fc_els_cmd_s));
  540. els_cmd->els_code = FC_ELS_ACC;
  541. return sizeof(struct fc_els_cmd_s);
  542. }
  543. int
  544. fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code)
  545. {
  546. int num_pages = 0;
  547. struct fc_prlo_s *prlo;
  548. struct fc_tprlo_s *tprlo;
  549. if (els_code == FC_ELS_PRLO) {
  550. prlo = (struct fc_prlo_s *) (fc_frame + 1);
  551. num_pages = (be16_to_cpu(prlo->payload_len) - 4) / 16;
  552. } else {
  553. tprlo = (struct fc_tprlo_s *) (fc_frame + 1);
  554. num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
  555. }
  556. return num_pages;
  557. }
  558. u16
  559. fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
  560. u32 d_id, u32 s_id, __be16 ox_id, int num_pages)
  561. {
  562. int page;
  563. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  564. memset(tprlo_acc, 0, (num_pages * 16) + 4);
  565. tprlo_acc->command = FC_ELS_ACC;
  566. tprlo_acc->page_len = 0x10;
  567. tprlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
  568. for (page = 0; page < num_pages; page++) {
  569. tprlo_acc->tprlo_acc_params[page].opa_valid = 0;
  570. tprlo_acc->tprlo_acc_params[page].rpa_valid = 0;
  571. tprlo_acc->tprlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
  572. tprlo_acc->tprlo_acc_params[page].orig_process_assc = 0;
  573. tprlo_acc->tprlo_acc_params[page].resp_process_assc = 0;
  574. }
  575. return be16_to_cpu(tprlo_acc->payload_len);
  576. }
  577. u16
  578. fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id,
  579. u32 s_id, __be16 ox_id, int num_pages)
  580. {
  581. int page;
  582. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  583. memset(prlo_acc, 0, (num_pages * 16) + 4);
  584. prlo_acc->command = FC_ELS_ACC;
  585. prlo_acc->page_len = 0x10;
  586. prlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
  587. for (page = 0; page < num_pages; page++) {
  588. prlo_acc->prlo_acc_params[page].opa_valid = 0;
  589. prlo_acc->prlo_acc_params[page].rpa_valid = 0;
  590. prlo_acc->prlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
  591. prlo_acc->prlo_acc_params[page].orig_process_assc = 0;
  592. prlo_acc->prlo_acc_params[page].resp_process_assc = 0;
  593. }
  594. return be16_to_cpu(prlo_acc->payload_len);
  595. }
  596. u16
  597. fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid, u32 d_id,
  598. u32 s_id, u16 ox_id, u32 data_format)
  599. {
  600. fc_els_req_build(fchs, d_id, s_id, ox_id);
  601. memset(rnid, 0, sizeof(struct fc_rnid_cmd_s));
  602. rnid->els_cmd.els_code = FC_ELS_RNID;
  603. rnid->node_id_data_format = data_format;
  604. return sizeof(struct fc_rnid_cmd_s);
  605. }
  606. u16
  607. fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id,
  608. u32 s_id, __be16 ox_id, u32 data_format,
  609. struct fc_rnid_common_id_data_s *common_id_data,
  610. struct fc_rnid_general_topology_data_s *gen_topo_data)
  611. {
  612. memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s));
  613. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  614. rnid_acc->els_cmd.els_code = FC_ELS_ACC;
  615. rnid_acc->node_id_data_format = data_format;
  616. rnid_acc->common_id_data_length =
  617. sizeof(struct fc_rnid_common_id_data_s);
  618. rnid_acc->common_id_data = *common_id_data;
  619. if (data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
  620. rnid_acc->specific_id_data_length =
  621. sizeof(struct fc_rnid_general_topology_data_s);
  622. rnid_acc->gen_topology_data = *gen_topo_data;
  623. return sizeof(struct fc_rnid_acc_s);
  624. } else {
  625. return sizeof(struct fc_rnid_acc_s) -
  626. sizeof(struct fc_rnid_general_topology_data_s);
  627. }
  628. }
  629. u16
  630. fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc, u32 d_id,
  631. u32 s_id, u16 ox_id)
  632. {
  633. fc_els_req_build(fchs, d_id, s_id, ox_id);
  634. memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s));
  635. rpsc->els_cmd.els_code = FC_ELS_RPSC;
  636. return sizeof(struct fc_rpsc_cmd_s);
  637. }
  638. u16
  639. fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rpsc2, u32 d_id,
  640. u32 s_id, u32 *pid_list, u16 npids)
  641. {
  642. u32 dctlr_id = FC_DOMAIN_CTRLR(bfa_hton3b(d_id));
  643. int i = 0;
  644. fc_els_req_build(fchs, bfa_hton3b(dctlr_id), s_id, 0);
  645. memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s));
  646. rpsc2->els_cmd.els_code = FC_ELS_RPSC;
  647. rpsc2->token = cpu_to_be32(FC_BRCD_TOKEN);
  648. rpsc2->num_pids = cpu_to_be16(npids);
  649. for (i = 0; i < npids; i++)
  650. rpsc2->pid_list[i].pid = pid_list[i];
  651. return sizeof(struct fc_rpsc2_cmd_s) + ((npids - 1) * (sizeof(u32)));
  652. }
  653. u16
  654. fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
  655. u32 d_id, u32 s_id, __be16 ox_id,
  656. struct fc_rpsc_speed_info_s *oper_speed)
  657. {
  658. memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s));
  659. fc_els_rsp_build(fchs, d_id, s_id, ox_id);
  660. rpsc_acc->command = FC_ELS_ACC;
  661. rpsc_acc->num_entries = cpu_to_be16(1);
  662. rpsc_acc->speed_info[0].port_speed_cap =
  663. cpu_to_be16(oper_speed->port_speed_cap);
  664. rpsc_acc->speed_info[0].port_op_speed =
  665. cpu_to_be16(oper_speed->port_op_speed);
  666. return sizeof(struct fc_rpsc_acc_s);
  667. }
  668. u16
  669. fc_logo_rsp_parse(struct fchs_s *fchs, int len)
  670. {
  671. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  672. len = len;
  673. if (els_cmd->els_code != FC_ELS_ACC)
  674. return FC_PARSE_FAILURE;
  675. return FC_PARSE_OK;
  676. }
  677. u16
  678. fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
  679. wwn_t port_name, wwn_t node_name, u16 pdu_size)
  680. {
  681. struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
  682. memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s));
  683. pdisc->els_cmd.els_code = FC_ELS_PDISC;
  684. fc_els_req_build(fchs, d_id, s_id, ox_id);
  685. pdisc->csp.rxsz = pdisc->class3.rxsz = cpu_to_be16(pdu_size);
  686. pdisc->port_name = port_name;
  687. pdisc->node_name = node_name;
  688. return sizeof(struct fc_logi_s);
  689. }
  690. u16
  691. fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
  692. {
  693. struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
  694. if (len < sizeof(struct fc_logi_s))
  695. return FC_PARSE_LEN_INVAL;
  696. if (pdisc->els_cmd.els_code != FC_ELS_ACC)
  697. return FC_PARSE_ACC_INVAL;
  698. if (!wwn_is_equal(pdisc->port_name, port_name))
  699. return FC_PARSE_PWWN_NOT_EQUAL;
  700. if (!pdisc->class3.class_valid)
  701. return FC_PARSE_NWWN_NOT_EQUAL;
  702. if (be16_to_cpu(pdisc->class3.rxsz) < (FC_MIN_PDUSZ))
  703. return FC_PARSE_RXSZ_INVAL;
  704. return FC_PARSE_OK;
  705. }
  706. u16
  707. fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
  708. int num_pages)
  709. {
  710. struct fc_prlo_s *prlo = (struct fc_prlo_s *) (fchs + 1);
  711. int page;
  712. fc_els_req_build(fchs, d_id, s_id, ox_id);
  713. memset(prlo, 0, (num_pages * 16) + 4);
  714. prlo->command = FC_ELS_PRLO;
  715. prlo->page_len = 0x10;
  716. prlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
  717. for (page = 0; page < num_pages; page++) {
  718. prlo->prlo_params[page].type = FC_TYPE_FCP;
  719. prlo->prlo_params[page].opa_valid = 0;
  720. prlo->prlo_params[page].rpa_valid = 0;
  721. prlo->prlo_params[page].orig_process_assc = 0;
  722. prlo->prlo_params[page].resp_process_assc = 0;
  723. }
  724. return be16_to_cpu(prlo->payload_len);
  725. }
  726. u16
  727. fc_prlo_rsp_parse(struct fchs_s *fchs, int len)
  728. {
  729. struct fc_prlo_acc_s *prlo = (struct fc_prlo_acc_s *) (fchs + 1);
  730. int num_pages = 0;
  731. int page = 0;
  732. len = len;
  733. if (prlo->command != FC_ELS_ACC)
  734. return FC_PARSE_FAILURE;
  735. num_pages = ((be16_to_cpu(prlo->payload_len)) - 4) / 16;
  736. for (page = 0; page < num_pages; page++) {
  737. if (prlo->prlo_acc_params[page].type != FC_TYPE_FCP)
  738. return FC_PARSE_FAILURE;
  739. if (prlo->prlo_acc_params[page].opa_valid != 0)
  740. return FC_PARSE_FAILURE;
  741. if (prlo->prlo_acc_params[page].rpa_valid != 0)
  742. return FC_PARSE_FAILURE;
  743. if (prlo->prlo_acc_params[page].orig_process_assc != 0)
  744. return FC_PARSE_FAILURE;
  745. if (prlo->prlo_acc_params[page].resp_process_assc != 0)
  746. return FC_PARSE_FAILURE;
  747. }
  748. return FC_PARSE_OK;
  749. }
  750. u16
  751. fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
  752. int num_pages, enum fc_tprlo_type tprlo_type, u32 tpr_id)
  753. {
  754. struct fc_tprlo_s *tprlo = (struct fc_tprlo_s *) (fchs + 1);
  755. int page;
  756. fc_els_req_build(fchs, d_id, s_id, ox_id);
  757. memset(tprlo, 0, (num_pages * 16) + 4);
  758. tprlo->command = FC_ELS_TPRLO;
  759. tprlo->page_len = 0x10;
  760. tprlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
  761. for (page = 0; page < num_pages; page++) {
  762. tprlo->tprlo_params[page].type = FC_TYPE_FCP;
  763. tprlo->tprlo_params[page].opa_valid = 0;
  764. tprlo->tprlo_params[page].rpa_valid = 0;
  765. tprlo->tprlo_params[page].orig_process_assc = 0;
  766. tprlo->tprlo_params[page].resp_process_assc = 0;
  767. if (tprlo_type == FC_GLOBAL_LOGO) {
  768. tprlo->tprlo_params[page].global_process_logout = 1;
  769. } else if (tprlo_type == FC_TPR_LOGO) {
  770. tprlo->tprlo_params[page].tpo_nport_valid = 1;
  771. tprlo->tprlo_params[page].tpo_nport_id = (tpr_id);
  772. }
  773. }
  774. return be16_to_cpu(tprlo->payload_len);
  775. }
  776. u16
  777. fc_tprlo_rsp_parse(struct fchs_s *fchs, int len)
  778. {
  779. struct fc_tprlo_acc_s *tprlo = (struct fc_tprlo_acc_s *) (fchs + 1);
  780. int num_pages = 0;
  781. int page = 0;
  782. len = len;
  783. if (tprlo->command != FC_ELS_ACC)
  784. return FC_PARSE_ACC_INVAL;
  785. num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
  786. for (page = 0; page < num_pages; page++) {
  787. if (tprlo->tprlo_acc_params[page].type != FC_TYPE_FCP)
  788. return FC_PARSE_NOT_FCP;
  789. if (tprlo->tprlo_acc_params[page].opa_valid != 0)
  790. return FC_PARSE_OPAFLAG_INVAL;
  791. if (tprlo->tprlo_acc_params[page].rpa_valid != 0)
  792. return FC_PARSE_RPAFLAG_INVAL;
  793. if (tprlo->tprlo_acc_params[page].orig_process_assc != 0)
  794. return FC_PARSE_OPA_INVAL;
  795. if (tprlo->tprlo_acc_params[page].resp_process_assc != 0)
  796. return FC_PARSE_RPA_INVAL;
  797. }
  798. return FC_PARSE_OK;
  799. }
  800. enum fc_parse_status
  801. fc_rrq_rsp_parse(struct fchs_s *fchs, int len)
  802. {
  803. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  804. len = len;
  805. if (els_cmd->els_code != FC_ELS_ACC)
  806. return FC_PARSE_FAILURE;
  807. return FC_PARSE_OK;
  808. }
  809. u16
  810. fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id,
  811. u32 reason_code, u32 reason_expl)
  812. {
  813. struct fc_ba_rjt_s *ba_rjt = (struct fc_ba_rjt_s *) (fchs + 1);
  814. fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
  815. fchs->cat_info = FC_CAT_BA_RJT;
  816. ba_rjt->reason_code = reason_code;
  817. ba_rjt->reason_expl = reason_expl;
  818. return sizeof(struct fc_ba_rjt_s);
  819. }
  820. static void
  821. fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
  822. {
  823. memset(cthdr, 0, sizeof(struct ct_hdr_s));
  824. cthdr->rev_id = CT_GS3_REVISION;
  825. cthdr->gs_type = CT_GSTYPE_DIRSERVICE;
  826. cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER;
  827. cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
  828. }
  829. static void
  830. fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
  831. {
  832. memset(cthdr, 0, sizeof(struct ct_hdr_s));
  833. cthdr->rev_id = CT_GS3_REVISION;
  834. cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
  835. cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER;
  836. cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
  837. }
  838. static void
  839. fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code,
  840. u8 sub_type)
  841. {
  842. memset(cthdr, 0, sizeof(struct ct_hdr_s));
  843. cthdr->rev_id = CT_GS3_REVISION;
  844. cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
  845. cthdr->gs_sub_type = sub_type;
  846. cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
  847. }
  848. u16
  849. fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
  850. wwn_t port_name)
  851. {
  852. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  853. struct fcgs_gidpn_req_s *gidpn = (struct fcgs_gidpn_req_s *)(cthdr + 1);
  854. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  855. fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
  856. fc_gs_cthdr_build(cthdr, s_id, GS_GID_PN);
  857. memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s));
  858. gidpn->port_name = port_name;
  859. return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s);
  860. }
  861. u16
  862. fc_gpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
  863. u32 port_id)
  864. {
  865. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  866. fcgs_gpnid_req_t *gpnid = (fcgs_gpnid_req_t *) (cthdr + 1);
  867. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  868. fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
  869. fc_gs_cthdr_build(cthdr, s_id, GS_GPN_ID);
  870. memset(gpnid, 0, sizeof(fcgs_gpnid_req_t));
  871. gpnid->dap = port_id;
  872. return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s);
  873. }
  874. u16
  875. fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
  876. u32 port_id)
  877. {
  878. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  879. fcgs_gnnid_req_t *gnnid = (fcgs_gnnid_req_t *) (cthdr + 1);
  880. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  881. fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
  882. fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID);
  883. memset(gnnid, 0, sizeof(fcgs_gnnid_req_t));
  884. gnnid->dap = port_id;
  885. return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s);
  886. }
  887. u16
  888. fc_ct_rsp_parse(struct ct_hdr_s *cthdr)
  889. {
  890. if (be16_to_cpu(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) {
  891. if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY)
  892. return FC_PARSE_BUSY;
  893. else
  894. return FC_PARSE_FAILURE;
  895. }
  896. return FC_PARSE_OK;
  897. }
  898. u16
  899. fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
  900. u32 d_id, u32 s_id, u16 ox_id, u8 reason_code,
  901. u8 reason_code_expl)
  902. {
  903. fc_gsresp_fchdr_build(fchs, d_id, s_id, ox_id);
  904. cthdr->cmd_rsp_code = cpu_to_be16(CT_RSP_REJECT);
  905. cthdr->rev_id = CT_GS3_REVISION;
  906. cthdr->reason_code = reason_code;
  907. cthdr->exp_code = reason_code_expl;
  908. return sizeof(struct ct_hdr_s);
  909. }
  910. u16
  911. fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
  912. u8 set_br_reg, u32 s_id, u16 ox_id)
  913. {
  914. u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
  915. fc_els_req_build(fchs, d_id, s_id, ox_id);
  916. memset(scr, 0, sizeof(struct fc_scr_s));
  917. scr->command = FC_ELS_SCR;
  918. scr->reg_func = FC_SCR_REG_FUNC_FULL;
  919. if (set_br_reg)
  920. scr->vu_reg_func = FC_VU_SCR_REG_FUNC_FABRIC_NAME_CHANGE;
  921. return sizeof(struct fc_scr_s);
  922. }
  923. u16
  924. fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
  925. u32 s_id, u16 ox_id)
  926. {
  927. u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
  928. u16 payldlen;
  929. fc_els_req_build(fchs, d_id, s_id, ox_id);
  930. rscn->command = FC_ELS_RSCN;
  931. rscn->pagelen = sizeof(rscn->event[0]);
  932. payldlen = sizeof(u32) + rscn->pagelen;
  933. rscn->payldlen = cpu_to_be16(payldlen);
  934. rscn->event[0].format = FC_RSCN_FORMAT_PORTID;
  935. rscn->event[0].portid = s_id;
  936. return sizeof(struct fc_rscn_pl_s);
  937. }
  938. u16
  939. fc_rftid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
  940. enum bfa_lport_role roles)
  941. {
  942. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  943. struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
  944. u32 type_value, d_id = bfa_hton3b(FC_NAME_SERVER);
  945. u8 index;
  946. fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
  947. fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
  948. memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
  949. rftid->dap = s_id;
  950. /* By default, FCP FC4 Type is registered */
  951. index = FC_TYPE_FCP >> 5;
  952. type_value = 1 << (FC_TYPE_FCP % 32);
  953. rftid->fc4_type[index] = cpu_to_be32(type_value);
  954. return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
  955. }
  956. u16
  957. fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
  958. u8 *fc4_bitmap, u32 bitmap_size)
  959. {
  960. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  961. struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
  962. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  963. fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
  964. fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
  965. memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
  966. rftid->dap = s_id;
  967. memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap,
  968. (bitmap_size < 32 ? bitmap_size : 32));
  969. return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
  970. }
  971. u16
  972. fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
  973. u8 fc4_type, u8 fc4_ftrs)
  974. {
  975. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  976. struct fcgs_rffid_req_s *rffid = (struct fcgs_rffid_req_s *)(cthdr + 1);
  977. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  978. fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
  979. fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID);
  980. memset(rffid, 0, sizeof(struct fcgs_rffid_req_s));
  981. rffid->dap = s_id;
  982. rffid->fc4ftr_bits = fc4_ftrs;
  983. rffid->fc4_type = fc4_type;
  984. return sizeof(struct fcgs_rffid_req_s) + sizeof(struct ct_hdr_s);
  985. }
  986. u16
  987. fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
  988. u8 *name)
  989. {
  990. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  991. struct fcgs_rspnid_req_s *rspnid =
  992. (struct fcgs_rspnid_req_s *)(cthdr + 1);
  993. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  994. fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
  995. fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID);
  996. memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
  997. rspnid->dap = s_id;
  998. strlcpy(rspnid->spn, name, sizeof(rspnid->spn));
  999. rspnid->spn_len = (u8) strlen(rspnid->spn);
  1000. return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
  1001. }
  1002. u16
  1003. fc_rsnn_nn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  1004. wwn_t node_name, u8 *name)
  1005. {
  1006. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1007. struct fcgs_rsnn_nn_req_s *rsnn_nn =
  1008. (struct fcgs_rsnn_nn_req_s *) (cthdr + 1);
  1009. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  1010. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1011. fc_gs_cthdr_build(cthdr, s_id, GS_RSNN_NN);
  1012. memset(rsnn_nn, 0, sizeof(struct fcgs_rsnn_nn_req_s));
  1013. rsnn_nn->node_name = node_name;
  1014. strlcpy(rsnn_nn->snn, name, sizeof(rsnn_nn->snn));
  1015. rsnn_nn->snn_len = (u8) strlen(rsnn_nn->snn);
  1016. return sizeof(struct fcgs_rsnn_nn_req_s) + sizeof(struct ct_hdr_s);
  1017. }
  1018. u16
  1019. fc_gid_ft_build(struct fchs_s *fchs, void *pyld, u32 s_id, u8 fc4_type)
  1020. {
  1021. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1022. struct fcgs_gidft_req_s *gidft = (struct fcgs_gidft_req_s *)(cthdr + 1);
  1023. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  1024. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1025. fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT);
  1026. memset(gidft, 0, sizeof(struct fcgs_gidft_req_s));
  1027. gidft->fc4_type = fc4_type;
  1028. gidft->domain_id = 0;
  1029. gidft->area_id = 0;
  1030. return sizeof(struct fcgs_gidft_req_s) + sizeof(struct ct_hdr_s);
  1031. }
  1032. u16
  1033. fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
  1034. wwn_t port_name)
  1035. {
  1036. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1037. struct fcgs_rpnid_req_s *rpnid = (struct fcgs_rpnid_req_s *)(cthdr + 1);
  1038. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  1039. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1040. fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID);
  1041. memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s));
  1042. rpnid->port_id = port_id;
  1043. rpnid->port_name = port_name;
  1044. return sizeof(struct fcgs_rpnid_req_s) + sizeof(struct ct_hdr_s);
  1045. }
  1046. u16
  1047. fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
  1048. wwn_t node_name)
  1049. {
  1050. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1051. struct fcgs_rnnid_req_s *rnnid = (struct fcgs_rnnid_req_s *)(cthdr + 1);
  1052. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  1053. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1054. fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID);
  1055. memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s));
  1056. rnnid->port_id = port_id;
  1057. rnnid->node_name = node_name;
  1058. return sizeof(struct fcgs_rnnid_req_s) + sizeof(struct ct_hdr_s);
  1059. }
  1060. u16
  1061. fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
  1062. u32 cos)
  1063. {
  1064. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1065. struct fcgs_rcsid_req_s *rcsid =
  1066. (struct fcgs_rcsid_req_s *) (cthdr + 1);
  1067. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  1068. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1069. fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID);
  1070. memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s));
  1071. rcsid->port_id = port_id;
  1072. rcsid->cos = cos;
  1073. return sizeof(struct fcgs_rcsid_req_s) + sizeof(struct ct_hdr_s);
  1074. }
  1075. u16
  1076. fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
  1077. u8 port_type)
  1078. {
  1079. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1080. struct fcgs_rptid_req_s *rptid = (struct fcgs_rptid_req_s *)(cthdr + 1);
  1081. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  1082. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1083. fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID);
  1084. memset(rptid, 0, sizeof(struct fcgs_rptid_req_s));
  1085. rptid->port_id = port_id;
  1086. rptid->port_type = port_type;
  1087. return sizeof(struct fcgs_rptid_req_s) + sizeof(struct ct_hdr_s);
  1088. }
  1089. u16
  1090. fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id)
  1091. {
  1092. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1093. struct fcgs_ganxt_req_s *ganxt = (struct fcgs_ganxt_req_s *)(cthdr + 1);
  1094. u32 d_id = bfa_hton3b(FC_NAME_SERVER);
  1095. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1096. fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT);
  1097. memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s));
  1098. ganxt->port_id = port_id;
  1099. return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s);
  1100. }
  1101. /*
  1102. * Builds fc hdr and ct hdr for FDMI requests.
  1103. */
  1104. u16
  1105. fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  1106. u16 cmd_code)
  1107. {
  1108. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1109. u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
  1110. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1111. fc_gs_fdmi_cthdr_build(cthdr, s_id, cmd_code);
  1112. return sizeof(struct ct_hdr_s);
  1113. }
  1114. /*
  1115. * Given a FC4 Type, this function returns a fc4 type bitmask
  1116. */
  1117. void
  1118. fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask)
  1119. {
  1120. u8 index;
  1121. __be32 *ptr = (__be32 *) bit_mask;
  1122. u32 type_value;
  1123. /*
  1124. * @todo : Check for bitmask size
  1125. */
  1126. index = fc4_type >> 5;
  1127. type_value = 1 << (fc4_type % 32);
  1128. ptr[index] = cpu_to_be32(type_value);
  1129. }
  1130. /*
  1131. * GMAL Request
  1132. */
  1133. u16
  1134. fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
  1135. {
  1136. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1137. fcgs_gmal_req_t *gmal = (fcgs_gmal_req_t *) (cthdr + 1);
  1138. u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
  1139. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1140. fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD,
  1141. CT_GSSUBTYPE_CFGSERVER);
  1142. memset(gmal, 0, sizeof(fcgs_gmal_req_t));
  1143. gmal->wwn = wwn;
  1144. return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t);
  1145. }
  1146. /*
  1147. * GFN (Get Fabric Name) Request
  1148. */
  1149. u16
  1150. fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
  1151. {
  1152. struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
  1153. fcgs_gfn_req_t *gfn = (fcgs_gfn_req_t *) (cthdr + 1);
  1154. u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
  1155. fc_gs_fchdr_build(fchs, d_id, s_id, 0);
  1156. fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD,
  1157. CT_GSSUBTYPE_CFGSERVER);
  1158. memset(gfn, 0, sizeof(fcgs_gfn_req_t));
  1159. gfn->wwn = wwn;
  1160. return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t);
  1161. }