qla_gs.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_target.h"
  9. #include <linux/utsname.h>
  10. static int qla2x00_sns_ga_nxt(scsi_qla_host_t *, fc_port_t *);
  11. static int qla2x00_sns_gid_pt(scsi_qla_host_t *, sw_info_t *);
  12. static int qla2x00_sns_gpn_id(scsi_qla_host_t *, sw_info_t *);
  13. static int qla2x00_sns_gnn_id(scsi_qla_host_t *, sw_info_t *);
  14. static int qla2x00_sns_rft_id(scsi_qla_host_t *);
  15. static int qla2x00_sns_rnn_id(scsi_qla_host_t *);
  16. /**
  17. * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query.
  18. * @ha: HA context
  19. * @req_size: request size in bytes
  20. * @rsp_size: response size in bytes
  21. *
  22. * Returns a pointer to the @ha's ms_iocb.
  23. */
  24. void *
  25. qla2x00_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size)
  26. {
  27. struct qla_hw_data *ha = vha->hw;
  28. ms_iocb_entry_t *ms_pkt;
  29. ms_pkt = ha->ms_iocb;
  30. memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
  31. ms_pkt->entry_type = MS_IOCB_TYPE;
  32. ms_pkt->entry_count = 1;
  33. SET_TARGET_ID(ha, ms_pkt->loop_id, SIMPLE_NAME_SERVER);
  34. ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
  35. ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  36. ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  37. ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
  38. ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
  39. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  40. ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  41. ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  42. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  43. ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  44. ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  45. ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
  46. vha->qla_stats.control_requests++;
  47. return (ms_pkt);
  48. }
  49. /**
  50. * qla24xx_prep_ms_iocb() - Prepare common CT IOCB fields for SNS CT query.
  51. * @ha: HA context
  52. * @req_size: request size in bytes
  53. * @rsp_size: response size in bytes
  54. *
  55. * Returns a pointer to the @ha's ms_iocb.
  56. */
  57. void *
  58. qla24xx_prep_ms_iocb(scsi_qla_host_t *vha, uint32_t req_size, uint32_t rsp_size)
  59. {
  60. struct qla_hw_data *ha = vha->hw;
  61. struct ct_entry_24xx *ct_pkt;
  62. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  63. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  64. ct_pkt->entry_type = CT_IOCB_TYPE;
  65. ct_pkt->entry_count = 1;
  66. ct_pkt->nport_handle = __constant_cpu_to_le16(NPH_SNS);
  67. ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  68. ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  69. ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
  70. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  71. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  72. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  73. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  74. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  75. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  76. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  77. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  78. ct_pkt->vp_index = vha->vp_idx;
  79. vha->qla_stats.control_requests++;
  80. return (ct_pkt);
  81. }
  82. /**
  83. * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
  84. * @ct_req: CT request buffer
  85. * @cmd: GS command
  86. * @rsp_size: response size in bytes
  87. *
  88. * Returns a pointer to the intitialized @ct_req.
  89. */
  90. static inline struct ct_sns_req *
  91. qla2x00_prep_ct_req(struct ct_sns_pkt *p, uint16_t cmd, uint16_t rsp_size)
  92. {
  93. memset(p, 0, sizeof(struct ct_sns_pkt));
  94. p->p.req.header.revision = 0x01;
  95. p->p.req.header.gs_type = 0xFC;
  96. p->p.req.header.gs_subtype = 0x02;
  97. p->p.req.command = cpu_to_be16(cmd);
  98. p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  99. return &p->p.req;
  100. }
  101. static int
  102. qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
  103. struct ct_sns_rsp *ct_rsp, const char *routine)
  104. {
  105. int rval;
  106. uint16_t comp_status;
  107. struct qla_hw_data *ha = vha->hw;
  108. rval = QLA_FUNCTION_FAILED;
  109. if (ms_pkt->entry_status != 0) {
  110. ql_dbg(ql_dbg_disc, vha, 0x2031,
  111. "%s failed, error status (%x) on port_id: %02x%02x%02x.\n",
  112. routine, ms_pkt->entry_status, vha->d_id.b.domain,
  113. vha->d_id.b.area, vha->d_id.b.al_pa);
  114. } else {
  115. if (IS_FWI2_CAPABLE(ha))
  116. comp_status = le16_to_cpu(
  117. ((struct ct_entry_24xx *)ms_pkt)->comp_status);
  118. else
  119. comp_status = le16_to_cpu(ms_pkt->status);
  120. switch (comp_status) {
  121. case CS_COMPLETE:
  122. case CS_DATA_UNDERRUN:
  123. case CS_DATA_OVERRUN: /* Overrun? */
  124. if (ct_rsp->header.response !=
  125. __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
  126. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2077,
  127. "%s failed rejected request on port_id: %02x%02x%02x Compeltion status 0x%x, response 0x%x\n",
  128. routine, vha->d_id.b.domain,
  129. vha->d_id.b.area, vha->d_id.b.al_pa,
  130. comp_status, ct_rsp->header.response);
  131. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha,
  132. 0x2078, (uint8_t *)&ct_rsp->header,
  133. sizeof(struct ct_rsp_hdr));
  134. rval = QLA_INVALID_COMMAND;
  135. } else
  136. rval = QLA_SUCCESS;
  137. break;
  138. default:
  139. ql_dbg(ql_dbg_disc, vha, 0x2033,
  140. "%s failed, completion status (%x) on port_id: "
  141. "%02x%02x%02x.\n", routine, comp_status,
  142. vha->d_id.b.domain, vha->d_id.b.area,
  143. vha->d_id.b.al_pa);
  144. break;
  145. }
  146. }
  147. return rval;
  148. }
  149. /**
  150. * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
  151. * @ha: HA context
  152. * @fcport: fcport entry to updated
  153. *
  154. * Returns 0 on success.
  155. */
  156. int
  157. qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
  158. {
  159. int rval;
  160. ms_iocb_entry_t *ms_pkt;
  161. struct ct_sns_req *ct_req;
  162. struct ct_sns_rsp *ct_rsp;
  163. struct qla_hw_data *ha = vha->hw;
  164. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  165. return qla2x00_sns_ga_nxt(vha, fcport);
  166. /* Issue GA_NXT */
  167. /* Prepare common MS IOCB */
  168. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GA_NXT_REQ_SIZE,
  169. GA_NXT_RSP_SIZE);
  170. /* Prepare CT request */
  171. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GA_NXT_CMD,
  172. GA_NXT_RSP_SIZE);
  173. ct_rsp = &ha->ct_sns->p.rsp;
  174. /* Prepare CT arguments -- port_id */
  175. ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
  176. ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
  177. ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
  178. /* Execute MS IOCB */
  179. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  180. sizeof(ms_iocb_entry_t));
  181. if (rval != QLA_SUCCESS) {
  182. /*EMPTY*/
  183. ql_dbg(ql_dbg_disc, vha, 0x2062,
  184. "GA_NXT issue IOCB failed (%d).\n", rval);
  185. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GA_NXT") !=
  186. QLA_SUCCESS) {
  187. rval = QLA_FUNCTION_FAILED;
  188. } else {
  189. /* Populate fc_port_t entry. */
  190. fcport->d_id.b.domain = ct_rsp->rsp.ga_nxt.port_id[0];
  191. fcport->d_id.b.area = ct_rsp->rsp.ga_nxt.port_id[1];
  192. fcport->d_id.b.al_pa = ct_rsp->rsp.ga_nxt.port_id[2];
  193. memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name,
  194. WWN_SIZE);
  195. memcpy(fcport->port_name, ct_rsp->rsp.ga_nxt.port_name,
  196. WWN_SIZE);
  197. fcport->fc4_type = (ct_rsp->rsp.ga_nxt.fc4_types[2] & BIT_0) ?
  198. FC4_TYPE_FCP_SCSI : FC4_TYPE_OTHER;
  199. if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE &&
  200. ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE)
  201. fcport->d_id.b.domain = 0xf0;
  202. ql_dbg(ql_dbg_disc, vha, 0x2063,
  203. "GA_NXT entry - nn %8phN pn %8phN "
  204. "port_id=%02x%02x%02x.\n",
  205. fcport->node_name, fcport->port_name,
  206. fcport->d_id.b.domain, fcport->d_id.b.area,
  207. fcport->d_id.b.al_pa);
  208. }
  209. return (rval);
  210. }
  211. static inline int
  212. qla2x00_gid_pt_rsp_size(scsi_qla_host_t *vha)
  213. {
  214. return vha->hw->max_fibre_devices * 4 + 16;
  215. }
  216. /**
  217. * qla2x00_gid_pt() - SNS scan for fabric devices via GID_PT command.
  218. * @ha: HA context
  219. * @list: switch info entries to populate
  220. *
  221. * NOTE: Non-Nx_Ports are not requested.
  222. *
  223. * Returns 0 on success.
  224. */
  225. int
  226. qla2x00_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
  227. {
  228. int rval;
  229. uint16_t i;
  230. ms_iocb_entry_t *ms_pkt;
  231. struct ct_sns_req *ct_req;
  232. struct ct_sns_rsp *ct_rsp;
  233. struct ct_sns_gid_pt_data *gid_data;
  234. struct qla_hw_data *ha = vha->hw;
  235. uint16_t gid_pt_rsp_size;
  236. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  237. return qla2x00_sns_gid_pt(vha, list);
  238. gid_data = NULL;
  239. gid_pt_rsp_size = qla2x00_gid_pt_rsp_size(vha);
  240. /* Issue GID_PT */
  241. /* Prepare common MS IOCB */
  242. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GID_PT_REQ_SIZE,
  243. gid_pt_rsp_size);
  244. /* Prepare CT request */
  245. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GID_PT_CMD, gid_pt_rsp_size);
  246. ct_rsp = &ha->ct_sns->p.rsp;
  247. /* Prepare CT arguments -- port_type */
  248. ct_req->req.gid_pt.port_type = NS_NX_PORT_TYPE;
  249. /* Execute MS IOCB */
  250. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  251. sizeof(ms_iocb_entry_t));
  252. if (rval != QLA_SUCCESS) {
  253. /*EMPTY*/
  254. ql_dbg(ql_dbg_disc, vha, 0x2055,
  255. "GID_PT issue IOCB failed (%d).\n", rval);
  256. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GID_PT") !=
  257. QLA_SUCCESS) {
  258. rval = QLA_FUNCTION_FAILED;
  259. } else {
  260. /* Set port IDs in switch info list. */
  261. for (i = 0; i < ha->max_fibre_devices; i++) {
  262. gid_data = &ct_rsp->rsp.gid_pt.entries[i];
  263. list[i].d_id.b.domain = gid_data->port_id[0];
  264. list[i].d_id.b.area = gid_data->port_id[1];
  265. list[i].d_id.b.al_pa = gid_data->port_id[2];
  266. memset(list[i].fabric_port_name, 0, WWN_SIZE);
  267. list[i].fp_speed = PORT_SPEED_UNKNOWN;
  268. /* Last one exit. */
  269. if (gid_data->control_byte & BIT_7) {
  270. list[i].d_id.b.rsvd_1 = gid_data->control_byte;
  271. break;
  272. }
  273. }
  274. /*
  275. * If we've used all available slots, then the switch is
  276. * reporting back more devices than we can handle with this
  277. * single call. Return a failed status, and let GA_NXT handle
  278. * the overload.
  279. */
  280. if (i == ha->max_fibre_devices)
  281. rval = QLA_FUNCTION_FAILED;
  282. }
  283. return (rval);
  284. }
  285. /**
  286. * qla2x00_gpn_id() - SNS Get Port Name (GPN_ID) query.
  287. * @ha: HA context
  288. * @list: switch info entries to populate
  289. *
  290. * Returns 0 on success.
  291. */
  292. int
  293. qla2x00_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
  294. {
  295. int rval = QLA_SUCCESS;
  296. uint16_t i;
  297. ms_iocb_entry_t *ms_pkt;
  298. struct ct_sns_req *ct_req;
  299. struct ct_sns_rsp *ct_rsp;
  300. struct qla_hw_data *ha = vha->hw;
  301. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  302. return qla2x00_sns_gpn_id(vha, list);
  303. for (i = 0; i < ha->max_fibre_devices; i++) {
  304. /* Issue GPN_ID */
  305. /* Prepare common MS IOCB */
  306. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GPN_ID_REQ_SIZE,
  307. GPN_ID_RSP_SIZE);
  308. /* Prepare CT request */
  309. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GPN_ID_CMD,
  310. GPN_ID_RSP_SIZE);
  311. ct_rsp = &ha->ct_sns->p.rsp;
  312. /* Prepare CT arguments -- port_id */
  313. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  314. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  315. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  316. /* Execute MS IOCB */
  317. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  318. sizeof(ms_iocb_entry_t));
  319. if (rval != QLA_SUCCESS) {
  320. /*EMPTY*/
  321. ql_dbg(ql_dbg_disc, vha, 0x2056,
  322. "GPN_ID issue IOCB failed (%d).\n", rval);
  323. break;
  324. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  325. "GPN_ID") != QLA_SUCCESS) {
  326. rval = QLA_FUNCTION_FAILED;
  327. break;
  328. } else {
  329. /* Save portname */
  330. memcpy(list[i].port_name,
  331. ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
  332. }
  333. /* Last device exit. */
  334. if (list[i].d_id.b.rsvd_1 != 0)
  335. break;
  336. }
  337. return (rval);
  338. }
  339. /**
  340. * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query.
  341. * @ha: HA context
  342. * @list: switch info entries to populate
  343. *
  344. * Returns 0 on success.
  345. */
  346. int
  347. qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
  348. {
  349. int rval = QLA_SUCCESS;
  350. uint16_t i;
  351. struct qla_hw_data *ha = vha->hw;
  352. ms_iocb_entry_t *ms_pkt;
  353. struct ct_sns_req *ct_req;
  354. struct ct_sns_rsp *ct_rsp;
  355. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  356. return qla2x00_sns_gnn_id(vha, list);
  357. for (i = 0; i < ha->max_fibre_devices; i++) {
  358. /* Issue GNN_ID */
  359. /* Prepare common MS IOCB */
  360. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GNN_ID_REQ_SIZE,
  361. GNN_ID_RSP_SIZE);
  362. /* Prepare CT request */
  363. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GNN_ID_CMD,
  364. GNN_ID_RSP_SIZE);
  365. ct_rsp = &ha->ct_sns->p.rsp;
  366. /* Prepare CT arguments -- port_id */
  367. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  368. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  369. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  370. /* Execute MS IOCB */
  371. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  372. sizeof(ms_iocb_entry_t));
  373. if (rval != QLA_SUCCESS) {
  374. /*EMPTY*/
  375. ql_dbg(ql_dbg_disc, vha, 0x2057,
  376. "GNN_ID issue IOCB failed (%d).\n", rval);
  377. break;
  378. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  379. "GNN_ID") != QLA_SUCCESS) {
  380. rval = QLA_FUNCTION_FAILED;
  381. break;
  382. } else {
  383. /* Save nodename */
  384. memcpy(list[i].node_name,
  385. ct_rsp->rsp.gnn_id.node_name, WWN_SIZE);
  386. ql_dbg(ql_dbg_disc, vha, 0x2058,
  387. "GID_PT entry - nn %8phN pn %8phN "
  388. "portid=%02x%02x%02x.\n",
  389. list[i].node_name, list[i].port_name,
  390. list[i].d_id.b.domain, list[i].d_id.b.area,
  391. list[i].d_id.b.al_pa);
  392. }
  393. /* Last device exit. */
  394. if (list[i].d_id.b.rsvd_1 != 0)
  395. break;
  396. }
  397. return (rval);
  398. }
  399. /**
  400. * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
  401. * @ha: HA context
  402. *
  403. * Returns 0 on success.
  404. */
  405. int
  406. qla2x00_rft_id(scsi_qla_host_t *vha)
  407. {
  408. int rval;
  409. struct qla_hw_data *ha = vha->hw;
  410. ms_iocb_entry_t *ms_pkt;
  411. struct ct_sns_req *ct_req;
  412. struct ct_sns_rsp *ct_rsp;
  413. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  414. return qla2x00_sns_rft_id(vha);
  415. /* Issue RFT_ID */
  416. /* Prepare common MS IOCB */
  417. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFT_ID_REQ_SIZE,
  418. RFT_ID_RSP_SIZE);
  419. /* Prepare CT request */
  420. ct_req = qla2x00_prep_ct_req(ha->ct_sns, RFT_ID_CMD,
  421. RFT_ID_RSP_SIZE);
  422. ct_rsp = &ha->ct_sns->p.rsp;
  423. /* Prepare CT arguments -- port_id, FC-4 types */
  424. ct_req->req.rft_id.port_id[0] = vha->d_id.b.domain;
  425. ct_req->req.rft_id.port_id[1] = vha->d_id.b.area;
  426. ct_req->req.rft_id.port_id[2] = vha->d_id.b.al_pa;
  427. ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */
  428. /* Execute MS IOCB */
  429. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  430. sizeof(ms_iocb_entry_t));
  431. if (rval != QLA_SUCCESS) {
  432. /*EMPTY*/
  433. ql_dbg(ql_dbg_disc, vha, 0x2043,
  434. "RFT_ID issue IOCB failed (%d).\n", rval);
  435. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFT_ID") !=
  436. QLA_SUCCESS) {
  437. rval = QLA_FUNCTION_FAILED;
  438. } else {
  439. ql_dbg(ql_dbg_disc, vha, 0x2044,
  440. "RFT_ID exiting normally.\n");
  441. }
  442. return (rval);
  443. }
  444. /**
  445. * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA.
  446. * @ha: HA context
  447. *
  448. * Returns 0 on success.
  449. */
  450. int
  451. qla2x00_rff_id(scsi_qla_host_t *vha)
  452. {
  453. int rval;
  454. struct qla_hw_data *ha = vha->hw;
  455. ms_iocb_entry_t *ms_pkt;
  456. struct ct_sns_req *ct_req;
  457. struct ct_sns_rsp *ct_rsp;
  458. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  459. ql_dbg(ql_dbg_disc, vha, 0x2046,
  460. "RFF_ID call not supported on ISP2100/ISP2200.\n");
  461. return (QLA_SUCCESS);
  462. }
  463. /* Issue RFF_ID */
  464. /* Prepare common MS IOCB */
  465. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RFF_ID_REQ_SIZE,
  466. RFF_ID_RSP_SIZE);
  467. /* Prepare CT request */
  468. ct_req = qla2x00_prep_ct_req(ha->ct_sns, RFF_ID_CMD,
  469. RFF_ID_RSP_SIZE);
  470. ct_rsp = &ha->ct_sns->p.rsp;
  471. /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
  472. ct_req->req.rff_id.port_id[0] = vha->d_id.b.domain;
  473. ct_req->req.rff_id.port_id[1] = vha->d_id.b.area;
  474. ct_req->req.rff_id.port_id[2] = vha->d_id.b.al_pa;
  475. qlt_rff_id(vha, ct_req);
  476. ct_req->req.rff_id.fc4_type = 0x08; /* SCSI - FCP */
  477. /* Execute MS IOCB */
  478. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  479. sizeof(ms_iocb_entry_t));
  480. if (rval != QLA_SUCCESS) {
  481. /*EMPTY*/
  482. ql_dbg(ql_dbg_disc, vha, 0x2047,
  483. "RFF_ID issue IOCB failed (%d).\n", rval);
  484. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RFF_ID") !=
  485. QLA_SUCCESS) {
  486. rval = QLA_FUNCTION_FAILED;
  487. } else {
  488. ql_dbg(ql_dbg_disc, vha, 0x2048,
  489. "RFF_ID exiting normally.\n");
  490. }
  491. return (rval);
  492. }
  493. /**
  494. * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
  495. * @ha: HA context
  496. *
  497. * Returns 0 on success.
  498. */
  499. int
  500. qla2x00_rnn_id(scsi_qla_host_t *vha)
  501. {
  502. int rval;
  503. struct qla_hw_data *ha = vha->hw;
  504. ms_iocb_entry_t *ms_pkt;
  505. struct ct_sns_req *ct_req;
  506. struct ct_sns_rsp *ct_rsp;
  507. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  508. return qla2x00_sns_rnn_id(vha);
  509. /* Issue RNN_ID */
  510. /* Prepare common MS IOCB */
  511. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, RNN_ID_REQ_SIZE,
  512. RNN_ID_RSP_SIZE);
  513. /* Prepare CT request */
  514. ct_req = qla2x00_prep_ct_req(ha->ct_sns, RNN_ID_CMD, RNN_ID_RSP_SIZE);
  515. ct_rsp = &ha->ct_sns->p.rsp;
  516. /* Prepare CT arguments -- port_id, node_name */
  517. ct_req->req.rnn_id.port_id[0] = vha->d_id.b.domain;
  518. ct_req->req.rnn_id.port_id[1] = vha->d_id.b.area;
  519. ct_req->req.rnn_id.port_id[2] = vha->d_id.b.al_pa;
  520. memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE);
  521. /* Execute MS IOCB */
  522. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  523. sizeof(ms_iocb_entry_t));
  524. if (rval != QLA_SUCCESS) {
  525. /*EMPTY*/
  526. ql_dbg(ql_dbg_disc, vha, 0x204d,
  527. "RNN_ID issue IOCB failed (%d).\n", rval);
  528. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RNN_ID") !=
  529. QLA_SUCCESS) {
  530. rval = QLA_FUNCTION_FAILED;
  531. } else {
  532. ql_dbg(ql_dbg_disc, vha, 0x204e,
  533. "RNN_ID exiting normally.\n");
  534. }
  535. return (rval);
  536. }
  537. void
  538. qla2x00_get_sym_node_name(scsi_qla_host_t *vha, uint8_t *snn, size_t size)
  539. {
  540. struct qla_hw_data *ha = vha->hw;
  541. if (IS_QLAFX00(ha))
  542. snprintf(snn, size, "%s FW:v%s DVR:v%s", ha->model_number,
  543. ha->mr.fw_version, qla2x00_version_str);
  544. else
  545. snprintf(snn, size,
  546. "%s FW:v%d.%02d.%02d DVR:v%s", ha->model_number,
  547. ha->fw_major_version, ha->fw_minor_version,
  548. ha->fw_subminor_version, qla2x00_version_str);
  549. }
  550. /**
  551. * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
  552. * @ha: HA context
  553. *
  554. * Returns 0 on success.
  555. */
  556. int
  557. qla2x00_rsnn_nn(scsi_qla_host_t *vha)
  558. {
  559. int rval;
  560. struct qla_hw_data *ha = vha->hw;
  561. ms_iocb_entry_t *ms_pkt;
  562. struct ct_sns_req *ct_req;
  563. struct ct_sns_rsp *ct_rsp;
  564. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  565. ql_dbg(ql_dbg_disc, vha, 0x2050,
  566. "RSNN_ID call unsupported on ISP2100/ISP2200.\n");
  567. return (QLA_SUCCESS);
  568. }
  569. /* Issue RSNN_NN */
  570. /* Prepare common MS IOCB */
  571. /* Request size adjusted after CT preparation */
  572. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, 0, RSNN_NN_RSP_SIZE);
  573. /* Prepare CT request */
  574. ct_req = qla2x00_prep_ct_req(ha->ct_sns, RSNN_NN_CMD,
  575. RSNN_NN_RSP_SIZE);
  576. ct_rsp = &ha->ct_sns->p.rsp;
  577. /* Prepare CT arguments -- node_name, symbolic node_name, size */
  578. memcpy(ct_req->req.rsnn_nn.node_name, vha->node_name, WWN_SIZE);
  579. /* Prepare the Symbolic Node Name */
  580. qla2x00_get_sym_node_name(vha, ct_req->req.rsnn_nn.sym_node_name,
  581. sizeof(ct_req->req.rsnn_nn.sym_node_name));
  582. /* Calculate SNN length */
  583. ct_req->req.rsnn_nn.name_len =
  584. (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name);
  585. /* Update MS IOCB request */
  586. ms_pkt->req_bytecount =
  587. cpu_to_le32(24 + 1 + ct_req->req.rsnn_nn.name_len);
  588. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  589. /* Execute MS IOCB */
  590. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  591. sizeof(ms_iocb_entry_t));
  592. if (rval != QLA_SUCCESS) {
  593. /*EMPTY*/
  594. ql_dbg(ql_dbg_disc, vha, 0x2051,
  595. "RSNN_NN issue IOCB failed (%d).\n", rval);
  596. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RSNN_NN") !=
  597. QLA_SUCCESS) {
  598. rval = QLA_FUNCTION_FAILED;
  599. } else {
  600. ql_dbg(ql_dbg_disc, vha, 0x2052,
  601. "RSNN_NN exiting normally.\n");
  602. }
  603. return (rval);
  604. }
  605. /**
  606. * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query.
  607. * @ha: HA context
  608. * @cmd: GS command
  609. * @scmd_len: Subcommand length
  610. * @data_size: response size in bytes
  611. *
  612. * Returns a pointer to the @ha's sns_cmd.
  613. */
  614. static inline struct sns_cmd_pkt *
  615. qla2x00_prep_sns_cmd(scsi_qla_host_t *vha, uint16_t cmd, uint16_t scmd_len,
  616. uint16_t data_size)
  617. {
  618. uint16_t wc;
  619. struct sns_cmd_pkt *sns_cmd;
  620. struct qla_hw_data *ha = vha->hw;
  621. sns_cmd = ha->sns_cmd;
  622. memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt));
  623. wc = data_size / 2; /* Size in 16bit words. */
  624. sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc);
  625. sns_cmd->p.cmd.buffer_address[0] = cpu_to_le32(LSD(ha->sns_cmd_dma));
  626. sns_cmd->p.cmd.buffer_address[1] = cpu_to_le32(MSD(ha->sns_cmd_dma));
  627. sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len);
  628. sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd);
  629. wc = (data_size - 16) / 4; /* Size in 32bit words. */
  630. sns_cmd->p.cmd.size = cpu_to_le16(wc);
  631. vha->qla_stats.control_requests++;
  632. return (sns_cmd);
  633. }
  634. /**
  635. * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
  636. * @ha: HA context
  637. * @fcport: fcport entry to updated
  638. *
  639. * This command uses the old Exectute SNS Command mailbox routine.
  640. *
  641. * Returns 0 on success.
  642. */
  643. static int
  644. qla2x00_sns_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
  645. {
  646. int rval = QLA_SUCCESS;
  647. struct qla_hw_data *ha = vha->hw;
  648. struct sns_cmd_pkt *sns_cmd;
  649. /* Issue GA_NXT. */
  650. /* Prepare SNS command request. */
  651. sns_cmd = qla2x00_prep_sns_cmd(vha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN,
  652. GA_NXT_SNS_DATA_SIZE);
  653. /* Prepare SNS command arguments -- port_id. */
  654. sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa;
  655. sns_cmd->p.cmd.param[1] = fcport->d_id.b.area;
  656. sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain;
  657. /* Execute SNS command. */
  658. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2,
  659. sizeof(struct sns_cmd_pkt));
  660. if (rval != QLA_SUCCESS) {
  661. /*EMPTY*/
  662. ql_dbg(ql_dbg_disc, vha, 0x205f,
  663. "GA_NXT Send SNS failed (%d).\n", rval);
  664. } else if (sns_cmd->p.gan_data[8] != 0x80 ||
  665. sns_cmd->p.gan_data[9] != 0x02) {
  666. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2084,
  667. "GA_NXT failed, rejected request ga_nxt_rsp:\n");
  668. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2074,
  669. sns_cmd->p.gan_data, 16);
  670. rval = QLA_FUNCTION_FAILED;
  671. } else {
  672. /* Populate fc_port_t entry. */
  673. fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
  674. fcport->d_id.b.area = sns_cmd->p.gan_data[18];
  675. fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
  676. memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
  677. memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
  678. if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
  679. sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
  680. fcport->d_id.b.domain = 0xf0;
  681. ql_dbg(ql_dbg_disc, vha, 0x2061,
  682. "GA_NXT entry - nn %8phN pn %8phN "
  683. "port_id=%02x%02x%02x.\n",
  684. fcport->node_name, fcport->port_name,
  685. fcport->d_id.b.domain, fcport->d_id.b.area,
  686. fcport->d_id.b.al_pa);
  687. }
  688. return (rval);
  689. }
  690. /**
  691. * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
  692. * @ha: HA context
  693. * @list: switch info entries to populate
  694. *
  695. * This command uses the old Exectute SNS Command mailbox routine.
  696. *
  697. * NOTE: Non-Nx_Ports are not requested.
  698. *
  699. * Returns 0 on success.
  700. */
  701. static int
  702. qla2x00_sns_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
  703. {
  704. int rval;
  705. struct qla_hw_data *ha = vha->hw;
  706. uint16_t i;
  707. uint8_t *entry;
  708. struct sns_cmd_pkt *sns_cmd;
  709. uint16_t gid_pt_sns_data_size;
  710. gid_pt_sns_data_size = qla2x00_gid_pt_rsp_size(vha);
  711. /* Issue GID_PT. */
  712. /* Prepare SNS command request. */
  713. sns_cmd = qla2x00_prep_sns_cmd(vha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
  714. gid_pt_sns_data_size);
  715. /* Prepare SNS command arguments -- port_type. */
  716. sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
  717. /* Execute SNS command. */
  718. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
  719. sizeof(struct sns_cmd_pkt));
  720. if (rval != QLA_SUCCESS) {
  721. /*EMPTY*/
  722. ql_dbg(ql_dbg_disc, vha, 0x206d,
  723. "GID_PT Send SNS failed (%d).\n", rval);
  724. } else if (sns_cmd->p.gid_data[8] != 0x80 ||
  725. sns_cmd->p.gid_data[9] != 0x02) {
  726. ql_dbg(ql_dbg_disc, vha, 0x202f,
  727. "GID_PT failed, rejected request, gid_rsp:\n");
  728. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2081,
  729. sns_cmd->p.gid_data, 16);
  730. rval = QLA_FUNCTION_FAILED;
  731. } else {
  732. /* Set port IDs in switch info list. */
  733. for (i = 0; i < ha->max_fibre_devices; i++) {
  734. entry = &sns_cmd->p.gid_data[(i * 4) + 16];
  735. list[i].d_id.b.domain = entry[1];
  736. list[i].d_id.b.area = entry[2];
  737. list[i].d_id.b.al_pa = entry[3];
  738. /* Last one exit. */
  739. if (entry[0] & BIT_7) {
  740. list[i].d_id.b.rsvd_1 = entry[0];
  741. break;
  742. }
  743. }
  744. /*
  745. * If we've used all available slots, then the switch is
  746. * reporting back more devices that we can handle with this
  747. * single call. Return a failed status, and let GA_NXT handle
  748. * the overload.
  749. */
  750. if (i == ha->max_fibre_devices)
  751. rval = QLA_FUNCTION_FAILED;
  752. }
  753. return (rval);
  754. }
  755. /**
  756. * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
  757. * @ha: HA context
  758. * @list: switch info entries to populate
  759. *
  760. * This command uses the old Exectute SNS Command mailbox routine.
  761. *
  762. * Returns 0 on success.
  763. */
  764. static int
  765. qla2x00_sns_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
  766. {
  767. int rval = QLA_SUCCESS;
  768. struct qla_hw_data *ha = vha->hw;
  769. uint16_t i;
  770. struct sns_cmd_pkt *sns_cmd;
  771. for (i = 0; i < ha->max_fibre_devices; i++) {
  772. /* Issue GPN_ID */
  773. /* Prepare SNS command request. */
  774. sns_cmd = qla2x00_prep_sns_cmd(vha, GPN_ID_CMD,
  775. GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
  776. /* Prepare SNS command arguments -- port_id. */
  777. sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
  778. sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
  779. sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
  780. /* Execute SNS command. */
  781. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
  782. GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
  783. if (rval != QLA_SUCCESS) {
  784. /*EMPTY*/
  785. ql_dbg(ql_dbg_disc, vha, 0x2032,
  786. "GPN_ID Send SNS failed (%d).\n", rval);
  787. } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
  788. sns_cmd->p.gpn_data[9] != 0x02) {
  789. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207e,
  790. "GPN_ID failed, rejected request, gpn_rsp:\n");
  791. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207f,
  792. sns_cmd->p.gpn_data, 16);
  793. rval = QLA_FUNCTION_FAILED;
  794. } else {
  795. /* Save portname */
  796. memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
  797. WWN_SIZE);
  798. }
  799. /* Last device exit. */
  800. if (list[i].d_id.b.rsvd_1 != 0)
  801. break;
  802. }
  803. return (rval);
  804. }
  805. /**
  806. * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
  807. * @ha: HA context
  808. * @list: switch info entries to populate
  809. *
  810. * This command uses the old Exectute SNS Command mailbox routine.
  811. *
  812. * Returns 0 on success.
  813. */
  814. static int
  815. qla2x00_sns_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
  816. {
  817. int rval = QLA_SUCCESS;
  818. struct qla_hw_data *ha = vha->hw;
  819. uint16_t i;
  820. struct sns_cmd_pkt *sns_cmd;
  821. for (i = 0; i < ha->max_fibre_devices; i++) {
  822. /* Issue GNN_ID */
  823. /* Prepare SNS command request. */
  824. sns_cmd = qla2x00_prep_sns_cmd(vha, GNN_ID_CMD,
  825. GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
  826. /* Prepare SNS command arguments -- port_id. */
  827. sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
  828. sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
  829. sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
  830. /* Execute SNS command. */
  831. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
  832. GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
  833. if (rval != QLA_SUCCESS) {
  834. /*EMPTY*/
  835. ql_dbg(ql_dbg_disc, vha, 0x203f,
  836. "GNN_ID Send SNS failed (%d).\n", rval);
  837. } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
  838. sns_cmd->p.gnn_data[9] != 0x02) {
  839. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2082,
  840. "GNN_ID failed, rejected request, gnn_rsp:\n");
  841. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207a,
  842. sns_cmd->p.gnn_data, 16);
  843. rval = QLA_FUNCTION_FAILED;
  844. } else {
  845. /* Save nodename */
  846. memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16],
  847. WWN_SIZE);
  848. ql_dbg(ql_dbg_disc, vha, 0x206e,
  849. "GID_PT entry - nn %8phN pn %8phN "
  850. "port_id=%02x%02x%02x.\n",
  851. list[i].node_name, list[i].port_name,
  852. list[i].d_id.b.domain, list[i].d_id.b.area,
  853. list[i].d_id.b.al_pa);
  854. }
  855. /* Last device exit. */
  856. if (list[i].d_id.b.rsvd_1 != 0)
  857. break;
  858. }
  859. return (rval);
  860. }
  861. /**
  862. * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
  863. * @ha: HA context
  864. *
  865. * This command uses the old Exectute SNS Command mailbox routine.
  866. *
  867. * Returns 0 on success.
  868. */
  869. static int
  870. qla2x00_sns_rft_id(scsi_qla_host_t *vha)
  871. {
  872. int rval;
  873. struct qla_hw_data *ha = vha->hw;
  874. struct sns_cmd_pkt *sns_cmd;
  875. /* Issue RFT_ID. */
  876. /* Prepare SNS command request. */
  877. sns_cmd = qla2x00_prep_sns_cmd(vha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
  878. RFT_ID_SNS_DATA_SIZE);
  879. /* Prepare SNS command arguments -- port_id, FC-4 types */
  880. sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
  881. sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
  882. sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
  883. sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
  884. /* Execute SNS command. */
  885. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
  886. sizeof(struct sns_cmd_pkt));
  887. if (rval != QLA_SUCCESS) {
  888. /*EMPTY*/
  889. ql_dbg(ql_dbg_disc, vha, 0x2060,
  890. "RFT_ID Send SNS failed (%d).\n", rval);
  891. } else if (sns_cmd->p.rft_data[8] != 0x80 ||
  892. sns_cmd->p.rft_data[9] != 0x02) {
  893. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2083,
  894. "RFT_ID failed, rejected request rft_rsp:\n");
  895. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2080,
  896. sns_cmd->p.rft_data, 16);
  897. rval = QLA_FUNCTION_FAILED;
  898. } else {
  899. ql_dbg(ql_dbg_disc, vha, 0x2073,
  900. "RFT_ID exiting normally.\n");
  901. }
  902. return (rval);
  903. }
  904. /**
  905. * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
  906. * HBA.
  907. * @ha: HA context
  908. *
  909. * This command uses the old Exectute SNS Command mailbox routine.
  910. *
  911. * Returns 0 on success.
  912. */
  913. static int
  914. qla2x00_sns_rnn_id(scsi_qla_host_t *vha)
  915. {
  916. int rval;
  917. struct qla_hw_data *ha = vha->hw;
  918. struct sns_cmd_pkt *sns_cmd;
  919. /* Issue RNN_ID. */
  920. /* Prepare SNS command request. */
  921. sns_cmd = qla2x00_prep_sns_cmd(vha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN,
  922. RNN_ID_SNS_DATA_SIZE);
  923. /* Prepare SNS command arguments -- port_id, nodename. */
  924. sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
  925. sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
  926. sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
  927. sns_cmd->p.cmd.param[4] = vha->node_name[7];
  928. sns_cmd->p.cmd.param[5] = vha->node_name[6];
  929. sns_cmd->p.cmd.param[6] = vha->node_name[5];
  930. sns_cmd->p.cmd.param[7] = vha->node_name[4];
  931. sns_cmd->p.cmd.param[8] = vha->node_name[3];
  932. sns_cmd->p.cmd.param[9] = vha->node_name[2];
  933. sns_cmd->p.cmd.param[10] = vha->node_name[1];
  934. sns_cmd->p.cmd.param[11] = vha->node_name[0];
  935. /* Execute SNS command. */
  936. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
  937. sizeof(struct sns_cmd_pkt));
  938. if (rval != QLA_SUCCESS) {
  939. /*EMPTY*/
  940. ql_dbg(ql_dbg_disc, vha, 0x204a,
  941. "RNN_ID Send SNS failed (%d).\n", rval);
  942. } else if (sns_cmd->p.rnn_data[8] != 0x80 ||
  943. sns_cmd->p.rnn_data[9] != 0x02) {
  944. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207b,
  945. "RNN_ID failed, rejected request, rnn_rsp:\n");
  946. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207c,
  947. sns_cmd->p.rnn_data, 16);
  948. rval = QLA_FUNCTION_FAILED;
  949. } else {
  950. ql_dbg(ql_dbg_disc, vha, 0x204c,
  951. "RNN_ID exiting normally.\n");
  952. }
  953. return (rval);
  954. }
  955. /**
  956. * qla2x00_mgmt_svr_login() - Login to fabric Management Service.
  957. * @ha: HA context
  958. *
  959. * Returns 0 on success.
  960. */
  961. static int
  962. qla2x00_mgmt_svr_login(scsi_qla_host_t *vha)
  963. {
  964. int ret, rval;
  965. uint16_t mb[MAILBOX_REGISTER_COUNT];
  966. struct qla_hw_data *ha = vha->hw;
  967. ret = QLA_SUCCESS;
  968. if (vha->flags.management_server_logged_in)
  969. return ret;
  970. rval = ha->isp_ops->fabric_login(vha, vha->mgmt_svr_loop_id, 0xff, 0xff,
  971. 0xfa, mb, BIT_1);
  972. if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
  973. if (rval == QLA_MEMORY_ALLOC_FAILED)
  974. ql_dbg(ql_dbg_disc, vha, 0x2085,
  975. "Failed management_server login: loopid=%x "
  976. "rval=%d\n", vha->mgmt_svr_loop_id, rval);
  977. else
  978. ql_dbg(ql_dbg_disc, vha, 0x2024,
  979. "Failed management_server login: loopid=%x "
  980. "mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x.\n",
  981. vha->mgmt_svr_loop_id, mb[0], mb[1], mb[2], mb[6],
  982. mb[7]);
  983. ret = QLA_FUNCTION_FAILED;
  984. } else
  985. vha->flags.management_server_logged_in = 1;
  986. return ret;
  987. }
  988. /**
  989. * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
  990. * @ha: HA context
  991. * @req_size: request size in bytes
  992. * @rsp_size: response size in bytes
  993. *
  994. * Returns a pointer to the @ha's ms_iocb.
  995. */
  996. void *
  997. qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
  998. uint32_t rsp_size)
  999. {
  1000. ms_iocb_entry_t *ms_pkt;
  1001. struct qla_hw_data *ha = vha->hw;
  1002. ms_pkt = ha->ms_iocb;
  1003. memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
  1004. ms_pkt->entry_type = MS_IOCB_TYPE;
  1005. ms_pkt->entry_count = 1;
  1006. SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id);
  1007. ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
  1008. ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  1009. ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  1010. ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
  1011. ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
  1012. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  1013. ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1014. ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1015. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  1016. ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1017. ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1018. ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
  1019. return ms_pkt;
  1020. }
  1021. /**
  1022. * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
  1023. * @ha: HA context
  1024. * @req_size: request size in bytes
  1025. * @rsp_size: response size in bytes
  1026. *
  1027. * Returns a pointer to the @ha's ms_iocb.
  1028. */
  1029. void *
  1030. qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
  1031. uint32_t rsp_size)
  1032. {
  1033. struct ct_entry_24xx *ct_pkt;
  1034. struct qla_hw_data *ha = vha->hw;
  1035. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1036. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  1037. ct_pkt->entry_type = CT_IOCB_TYPE;
  1038. ct_pkt->entry_count = 1;
  1039. ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
  1040. ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  1041. ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  1042. ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
  1043. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  1044. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1045. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1046. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1047. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1048. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1049. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1050. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  1051. ct_pkt->vp_index = vha->vp_idx;
  1052. return ct_pkt;
  1053. }
  1054. static inline ms_iocb_entry_t *
  1055. qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size)
  1056. {
  1057. struct qla_hw_data *ha = vha->hw;
  1058. ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
  1059. struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1060. if (IS_FWI2_CAPABLE(ha)) {
  1061. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1062. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1063. } else {
  1064. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  1065. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  1066. }
  1067. return ms_pkt;
  1068. }
  1069. /**
  1070. * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
  1071. * @ct_req: CT request buffer
  1072. * @cmd: GS command
  1073. * @rsp_size: response size in bytes
  1074. *
  1075. * Returns a pointer to the intitialized @ct_req.
  1076. */
  1077. static inline struct ct_sns_req *
  1078. qla2x00_prep_ct_fdmi_req(struct ct_sns_pkt *p, uint16_t cmd,
  1079. uint16_t rsp_size)
  1080. {
  1081. memset(p, 0, sizeof(struct ct_sns_pkt));
  1082. p->p.req.header.revision = 0x01;
  1083. p->p.req.header.gs_type = 0xFA;
  1084. p->p.req.header.gs_subtype = 0x10;
  1085. p->p.req.command = cpu_to_be16(cmd);
  1086. p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  1087. return &p->p.req;
  1088. }
  1089. /**
  1090. * qla2x00_fdmi_rhba() -
  1091. * @ha: HA context
  1092. *
  1093. * Returns 0 on success.
  1094. */
  1095. static int
  1096. qla2x00_fdmi_rhba(scsi_qla_host_t *vha)
  1097. {
  1098. int rval, alen;
  1099. uint32_t size, sn;
  1100. ms_iocb_entry_t *ms_pkt;
  1101. struct ct_sns_req *ct_req;
  1102. struct ct_sns_rsp *ct_rsp;
  1103. void *entries;
  1104. struct ct_fdmi_hba_attr *eiter;
  1105. struct qla_hw_data *ha = vha->hw;
  1106. /* Issue RHBA */
  1107. /* Prepare common MS IOCB */
  1108. /* Request size adjusted after CT preparation */
  1109. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
  1110. /* Prepare CT request */
  1111. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD, RHBA_RSP_SIZE);
  1112. ct_rsp = &ha->ct_sns->p.rsp;
  1113. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1114. memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, WWN_SIZE);
  1115. ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
  1116. memcpy(ct_req->req.rhba.port_name, vha->port_name, WWN_SIZE);
  1117. size = 2 * WWN_SIZE + 4 + 4;
  1118. /* Attributes */
  1119. ct_req->req.rhba.attrs.count =
  1120. __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
  1121. entries = ct_req->req.rhba.hba_identifier;
  1122. /* Nodename. */
  1123. eiter = entries + size;
  1124. eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
  1125. eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
  1126. memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
  1127. size += 4 + WWN_SIZE;
  1128. ql_dbg(ql_dbg_disc, vha, 0x2025,
  1129. "NodeName = %8phN.\n", eiter->a.node_name);
  1130. /* Manufacturer. */
  1131. eiter = entries + size;
  1132. eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
  1133. alen = strlen(QLA2XXX_MANUFACTURER);
  1134. snprintf(eiter->a.manufacturer, sizeof(eiter->a.manufacturer),
  1135. "%s", "QLogic Corporation");
  1136. alen += 4 - (alen & 3);
  1137. eiter->len = cpu_to_be16(4 + alen);
  1138. size += 4 + alen;
  1139. ql_dbg(ql_dbg_disc, vha, 0x2026,
  1140. "Manufacturer = %s.\n", eiter->a.manufacturer);
  1141. /* Serial number. */
  1142. eiter = entries + size;
  1143. eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
  1144. if (IS_FWI2_CAPABLE(ha))
  1145. qla2xxx_get_vpd_field(vha, "SN", eiter->a.serial_num,
  1146. sizeof(eiter->a.serial_num));
  1147. else {
  1148. sn = ((ha->serial0 & 0x1f) << 16) |
  1149. (ha->serial2 << 8) | ha->serial1;
  1150. snprintf(eiter->a.serial_num, sizeof(eiter->a.serial_num),
  1151. "%c%05d", 'A' + sn / 100000, sn % 100000);
  1152. }
  1153. alen = strlen(eiter->a.serial_num);
  1154. alen += 4 - (alen & 3);
  1155. eiter->len = cpu_to_be16(4 + alen);
  1156. size += 4 + alen;
  1157. ql_dbg(ql_dbg_disc, vha, 0x2027,
  1158. "Serial no. = %s.\n", eiter->a.serial_num);
  1159. /* Model name. */
  1160. eiter = entries + size;
  1161. eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
  1162. snprintf(eiter->a.model, sizeof(eiter->a.model),
  1163. "%s", ha->model_number);
  1164. alen = strlen(eiter->a.model);
  1165. alen += 4 - (alen & 3);
  1166. eiter->len = cpu_to_be16(4 + alen);
  1167. size += 4 + alen;
  1168. ql_dbg(ql_dbg_disc, vha, 0x2028,
  1169. "Model Name = %s.\n", eiter->a.model);
  1170. /* Model description. */
  1171. eiter = entries + size;
  1172. eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
  1173. snprintf(eiter->a.model_desc, sizeof(eiter->a.model_desc),
  1174. "%s", ha->model_desc);
  1175. alen = strlen(eiter->a.model_desc);
  1176. alen += 4 - (alen & 3);
  1177. eiter->len = cpu_to_be16(4 + alen);
  1178. size += 4 + alen;
  1179. ql_dbg(ql_dbg_disc, vha, 0x2029,
  1180. "Model Desc = %s.\n", eiter->a.model_desc);
  1181. /* Hardware version. */
  1182. eiter = entries + size;
  1183. eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
  1184. if (!IS_FWI2_CAPABLE(ha)) {
  1185. snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
  1186. "HW:%s", ha->adapter_id);
  1187. } else if (qla2xxx_get_vpd_field(vha, "MN", eiter->a.hw_version,
  1188. sizeof(eiter->a.hw_version))) {
  1189. ;
  1190. } else if (qla2xxx_get_vpd_field(vha, "EC", eiter->a.hw_version,
  1191. sizeof(eiter->a.hw_version))) {
  1192. ;
  1193. } else {
  1194. snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
  1195. "HW:%s", ha->adapter_id);
  1196. }
  1197. alen = strlen(eiter->a.hw_version);
  1198. alen += 4 - (alen & 3);
  1199. eiter->len = cpu_to_be16(4 + alen);
  1200. size += 4 + alen;
  1201. ql_dbg(ql_dbg_disc, vha, 0x202a,
  1202. "Hardware ver = %s.\n", eiter->a.hw_version);
  1203. /* Driver version. */
  1204. eiter = entries + size;
  1205. eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
  1206. snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version),
  1207. "%s", qla2x00_version_str);
  1208. alen = strlen(eiter->a.driver_version);
  1209. alen += 4 - (alen & 3);
  1210. eiter->len = cpu_to_be16(4 + alen);
  1211. size += 4 + alen;
  1212. ql_dbg(ql_dbg_disc, vha, 0x202b,
  1213. "Driver ver = %s.\n", eiter->a.driver_version);
  1214. /* Option ROM version. */
  1215. eiter = entries + size;
  1216. eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
  1217. snprintf(eiter->a.orom_version, sizeof(eiter->a.orom_version),
  1218. "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
  1219. alen = strlen(eiter->a.orom_version);
  1220. alen += 4 - (alen & 3);
  1221. eiter->len = cpu_to_be16(4 + alen);
  1222. size += 4 + alen;
  1223. ql_dbg(ql_dbg_disc, vha , 0x202c,
  1224. "Optrom vers = %s.\n", eiter->a.orom_version);
  1225. /* Firmware version */
  1226. eiter = entries + size;
  1227. eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
  1228. ha->isp_ops->fw_version_str(vha, eiter->a.fw_version,
  1229. sizeof(eiter->a.fw_version));
  1230. alen = strlen(eiter->a.fw_version);
  1231. alen += 4 - (alen & 3);
  1232. eiter->len = cpu_to_be16(4 + alen);
  1233. size += 4 + alen;
  1234. ql_dbg(ql_dbg_disc, vha, 0x202d,
  1235. "Firmware vers = %s.\n", eiter->a.fw_version);
  1236. /* Update MS request size. */
  1237. qla2x00_update_ms_fdmi_iocb(vha, size + 16);
  1238. ql_dbg(ql_dbg_disc, vha, 0x202e,
  1239. "RHBA identifier = %8phN size=%d.\n",
  1240. ct_req->req.rhba.hba_identifier, size);
  1241. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2076,
  1242. entries, size);
  1243. /* Execute MS IOCB */
  1244. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1245. sizeof(ms_iocb_entry_t));
  1246. if (rval != QLA_SUCCESS) {
  1247. /*EMPTY*/
  1248. ql_dbg(ql_dbg_disc, vha, 0x2030,
  1249. "RHBA issue IOCB failed (%d).\n", rval);
  1250. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
  1251. QLA_SUCCESS) {
  1252. rval = QLA_FUNCTION_FAILED;
  1253. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  1254. ct_rsp->header.explanation_code ==
  1255. CT_EXPL_ALREADY_REGISTERED) {
  1256. ql_dbg(ql_dbg_disc, vha, 0x2034,
  1257. "HBA already registered.\n");
  1258. rval = QLA_ALREADY_REGISTERED;
  1259. } else {
  1260. ql_dbg(ql_dbg_disc, vha, 0x20ad,
  1261. "RHBA FDMI registration failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
  1262. ct_rsp->header.reason_code,
  1263. ct_rsp->header.explanation_code);
  1264. }
  1265. } else {
  1266. ql_dbg(ql_dbg_disc, vha, 0x2035,
  1267. "RHBA exiting normally.\n");
  1268. }
  1269. return rval;
  1270. }
  1271. /**
  1272. * qla2x00_fdmi_rpa() -
  1273. * @ha: HA context
  1274. *
  1275. * Returns 0 on success.
  1276. */
  1277. static int
  1278. qla2x00_fdmi_rpa(scsi_qla_host_t *vha)
  1279. {
  1280. int rval, alen;
  1281. uint32_t size;
  1282. struct qla_hw_data *ha = vha->hw;
  1283. ms_iocb_entry_t *ms_pkt;
  1284. struct ct_sns_req *ct_req;
  1285. struct ct_sns_rsp *ct_rsp;
  1286. void *entries;
  1287. struct ct_fdmi_port_attr *eiter;
  1288. struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
  1289. struct new_utsname *p_sysid = NULL;
  1290. /* Issue RPA */
  1291. /* Prepare common MS IOCB */
  1292. /* Request size adjusted after CT preparation */
  1293. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
  1294. /* Prepare CT request */
  1295. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD,
  1296. RPA_RSP_SIZE);
  1297. ct_rsp = &ha->ct_sns->p.rsp;
  1298. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1299. memcpy(ct_req->req.rpa.port_name, vha->port_name, WWN_SIZE);
  1300. size = WWN_SIZE + 4;
  1301. /* Attributes */
  1302. ct_req->req.rpa.attrs.count = cpu_to_be32(FDMI_PORT_ATTR_COUNT);
  1303. entries = ct_req->req.rpa.port_name;
  1304. /* FC4 types. */
  1305. eiter = entries + size;
  1306. eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPES);
  1307. eiter->len = cpu_to_be16(4 + 32);
  1308. eiter->a.fc4_types[2] = 0x01;
  1309. size += 4 + 32;
  1310. ql_dbg(ql_dbg_disc, vha, 0x2039,
  1311. "FC4_TYPES=%02x %02x.\n",
  1312. eiter->a.fc4_types[2],
  1313. eiter->a.fc4_types[1]);
  1314. /* Supported speed. */
  1315. eiter = entries + size;
  1316. eiter->type = cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
  1317. eiter->len = cpu_to_be16(4 + 4);
  1318. if (IS_CNA_CAPABLE(ha))
  1319. eiter->a.sup_speed = cpu_to_be32(
  1320. FDMI_PORT_SPEED_10GB);
  1321. else if (IS_QLA27XX(ha))
  1322. eiter->a.sup_speed = cpu_to_be32(
  1323. FDMI_PORT_SPEED_32GB|
  1324. FDMI_PORT_SPEED_16GB|
  1325. FDMI_PORT_SPEED_8GB);
  1326. else if (IS_QLA2031(ha))
  1327. eiter->a.sup_speed = cpu_to_be32(
  1328. FDMI_PORT_SPEED_16GB|
  1329. FDMI_PORT_SPEED_8GB|
  1330. FDMI_PORT_SPEED_4GB);
  1331. else if (IS_QLA25XX(ha))
  1332. eiter->a.sup_speed = cpu_to_be32(
  1333. FDMI_PORT_SPEED_8GB|
  1334. FDMI_PORT_SPEED_4GB|
  1335. FDMI_PORT_SPEED_2GB|
  1336. FDMI_PORT_SPEED_1GB);
  1337. else if (IS_QLA24XX_TYPE(ha))
  1338. eiter->a.sup_speed = cpu_to_be32(
  1339. FDMI_PORT_SPEED_4GB|
  1340. FDMI_PORT_SPEED_2GB|
  1341. FDMI_PORT_SPEED_1GB);
  1342. else if (IS_QLA23XX(ha))
  1343. eiter->a.sup_speed = cpu_to_be32(
  1344. FDMI_PORT_SPEED_2GB|
  1345. FDMI_PORT_SPEED_1GB);
  1346. else
  1347. eiter->a.sup_speed = cpu_to_be32(
  1348. FDMI_PORT_SPEED_1GB);
  1349. size += 4 + 4;
  1350. ql_dbg(ql_dbg_disc, vha, 0x203a,
  1351. "Supported_Speed=%x.\n", eiter->a.sup_speed);
  1352. /* Current speed. */
  1353. eiter = entries + size;
  1354. eiter->type = cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
  1355. eiter->len = cpu_to_be16(4 + 4);
  1356. switch (ha->link_data_rate) {
  1357. case PORT_SPEED_1GB:
  1358. eiter->a.cur_speed =
  1359. cpu_to_be32(FDMI_PORT_SPEED_1GB);
  1360. break;
  1361. case PORT_SPEED_2GB:
  1362. eiter->a.cur_speed =
  1363. cpu_to_be32(FDMI_PORT_SPEED_2GB);
  1364. break;
  1365. case PORT_SPEED_4GB:
  1366. eiter->a.cur_speed =
  1367. cpu_to_be32(FDMI_PORT_SPEED_4GB);
  1368. break;
  1369. case PORT_SPEED_8GB:
  1370. eiter->a.cur_speed =
  1371. cpu_to_be32(FDMI_PORT_SPEED_8GB);
  1372. break;
  1373. case PORT_SPEED_10GB:
  1374. eiter->a.cur_speed =
  1375. cpu_to_be32(FDMI_PORT_SPEED_10GB);
  1376. break;
  1377. case PORT_SPEED_16GB:
  1378. eiter->a.cur_speed =
  1379. cpu_to_be32(FDMI_PORT_SPEED_16GB);
  1380. break;
  1381. case PORT_SPEED_32GB:
  1382. eiter->a.cur_speed =
  1383. cpu_to_be32(FDMI_PORT_SPEED_32GB);
  1384. break;
  1385. default:
  1386. eiter->a.cur_speed =
  1387. cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
  1388. break;
  1389. }
  1390. size += 4 + 4;
  1391. ql_dbg(ql_dbg_disc, vha, 0x203b,
  1392. "Current_Speed=%x.\n", eiter->a.cur_speed);
  1393. /* Max frame size. */
  1394. eiter = entries + size;
  1395. eiter->type = cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
  1396. eiter->len = cpu_to_be16(4 + 4);
  1397. eiter->a.max_frame_size = IS_FWI2_CAPABLE(ha) ?
  1398. le16_to_cpu(icb24->frame_payload_size) :
  1399. le16_to_cpu(ha->init_cb->frame_payload_size);
  1400. eiter->a.max_frame_size = cpu_to_be32(eiter->a.max_frame_size);
  1401. size += 4 + 4;
  1402. ql_dbg(ql_dbg_disc, vha, 0x203c,
  1403. "Max_Frame_Size=%x.\n", eiter->a.max_frame_size);
  1404. /* OS device name. */
  1405. eiter = entries + size;
  1406. eiter->type = cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
  1407. snprintf(eiter->a.os_dev_name, sizeof(eiter->a.os_dev_name),
  1408. "%s:host%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
  1409. alen = strlen(eiter->a.os_dev_name);
  1410. alen += 4 - (alen & 3);
  1411. eiter->len = cpu_to_be16(4 + alen);
  1412. size += 4 + alen;
  1413. ql_dbg(ql_dbg_disc, vha, 0x204b,
  1414. "OS_Device_Name=%s.\n", eiter->a.os_dev_name);
  1415. /* Hostname. */
  1416. eiter = entries + size;
  1417. eiter->type = cpu_to_be16(FDMI_PORT_HOST_NAME);
  1418. p_sysid = utsname();
  1419. if (p_sysid) {
  1420. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  1421. "%s", p_sysid->nodename);
  1422. } else {
  1423. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  1424. "%s", fc_host_system_hostname(vha->host));
  1425. }
  1426. alen = strlen(eiter->a.host_name);
  1427. alen += 4 - (alen & 3);
  1428. eiter->len = cpu_to_be16(4 + alen);
  1429. size += 4 + alen;
  1430. ql_dbg(ql_dbg_disc, vha, 0x203d, "HostName=%s.\n", eiter->a.host_name);
  1431. /* Update MS request size. */
  1432. qla2x00_update_ms_fdmi_iocb(vha, size + 16);
  1433. ql_dbg(ql_dbg_disc, vha, 0x203e,
  1434. "RPA portname %016llx, size = %d.\n",
  1435. wwn_to_u64(ct_req->req.rpa.port_name), size);
  1436. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2079,
  1437. entries, size);
  1438. /* Execute MS IOCB */
  1439. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1440. sizeof(ms_iocb_entry_t));
  1441. if (rval != QLA_SUCCESS) {
  1442. /*EMPTY*/
  1443. ql_dbg(ql_dbg_disc, vha, 0x2040,
  1444. "RPA issue IOCB failed (%d).\n", rval);
  1445. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
  1446. QLA_SUCCESS) {
  1447. rval = QLA_FUNCTION_FAILED;
  1448. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  1449. ct_rsp->header.explanation_code ==
  1450. CT_EXPL_ALREADY_REGISTERED) {
  1451. ql_dbg(ql_dbg_disc, vha, 0x20cd,
  1452. "RPA already registered.\n");
  1453. rval = QLA_ALREADY_REGISTERED;
  1454. }
  1455. } else {
  1456. ql_dbg(ql_dbg_disc, vha, 0x2041,
  1457. "RPA exiting normally.\n");
  1458. }
  1459. return rval;
  1460. }
  1461. /**
  1462. * qla2x00_fdmiv2_rhba() -
  1463. * @ha: HA context
  1464. *
  1465. * Returns 0 on success.
  1466. */
  1467. static int
  1468. qla2x00_fdmiv2_rhba(scsi_qla_host_t *vha)
  1469. {
  1470. int rval, alen;
  1471. uint32_t size, sn;
  1472. ms_iocb_entry_t *ms_pkt;
  1473. struct ct_sns_req *ct_req;
  1474. struct ct_sns_rsp *ct_rsp;
  1475. void *entries;
  1476. struct ct_fdmiv2_hba_attr *eiter;
  1477. struct qla_hw_data *ha = vha->hw;
  1478. struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
  1479. struct new_utsname *p_sysid = NULL;
  1480. /* Issue RHBA */
  1481. /* Prepare common MS IOCB */
  1482. /* Request size adjusted after CT preparation */
  1483. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
  1484. /* Prepare CT request */
  1485. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD,
  1486. RHBA_RSP_SIZE);
  1487. ct_rsp = &ha->ct_sns->p.rsp;
  1488. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1489. memcpy(ct_req->req.rhba2.hba_identifier, vha->port_name, WWN_SIZE);
  1490. ct_req->req.rhba2.entry_count = cpu_to_be32(1);
  1491. memcpy(ct_req->req.rhba2.port_name, vha->port_name, WWN_SIZE);
  1492. size = 2 * WWN_SIZE + 4 + 4;
  1493. /* Attributes */
  1494. ct_req->req.rhba2.attrs.count = cpu_to_be32(FDMIV2_HBA_ATTR_COUNT);
  1495. entries = ct_req->req.rhba2.hba_identifier;
  1496. /* Nodename. */
  1497. eiter = entries + size;
  1498. eiter->type = cpu_to_be16(FDMI_HBA_NODE_NAME);
  1499. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  1500. memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
  1501. size += 4 + WWN_SIZE;
  1502. ql_dbg(ql_dbg_disc, vha, 0x207d,
  1503. "NodeName = %016llx.\n", wwn_to_u64(eiter->a.node_name));
  1504. /* Manufacturer. */
  1505. eiter = entries + size;
  1506. eiter->type = cpu_to_be16(FDMI_HBA_MANUFACTURER);
  1507. snprintf(eiter->a.manufacturer, sizeof(eiter->a.manufacturer),
  1508. "%s", "QLogic Corporation");
  1509. eiter->a.manufacturer[strlen("QLogic Corporation")] = '\0';
  1510. alen = strlen(eiter->a.manufacturer);
  1511. alen += 4 - (alen & 3);
  1512. eiter->len = cpu_to_be16(4 + alen);
  1513. size += 4 + alen;
  1514. ql_dbg(ql_dbg_disc, vha, 0x20a5,
  1515. "Manufacturer = %s.\n", eiter->a.manufacturer);
  1516. /* Serial number. */
  1517. eiter = entries + size;
  1518. eiter->type = cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
  1519. if (IS_FWI2_CAPABLE(ha))
  1520. qla2xxx_get_vpd_field(vha, "SN", eiter->a.serial_num,
  1521. sizeof(eiter->a.serial_num));
  1522. else {
  1523. sn = ((ha->serial0 & 0x1f) << 16) |
  1524. (ha->serial2 << 8) | ha->serial1;
  1525. snprintf(eiter->a.serial_num, sizeof(eiter->a.serial_num),
  1526. "%c%05d", 'A' + sn / 100000, sn % 100000);
  1527. }
  1528. alen = strlen(eiter->a.serial_num);
  1529. alen += 4 - (alen & 3);
  1530. eiter->len = cpu_to_be16(4 + alen);
  1531. size += 4 + alen;
  1532. ql_dbg(ql_dbg_disc, vha, 0x20a6,
  1533. "Serial no. = %s.\n", eiter->a.serial_num);
  1534. /* Model name. */
  1535. eiter = entries + size;
  1536. eiter->type = cpu_to_be16(FDMI_HBA_MODEL);
  1537. snprintf(eiter->a.model, sizeof(eiter->a.model),
  1538. "%s", ha->model_number);
  1539. alen = strlen(eiter->a.model);
  1540. alen += 4 - (alen & 3);
  1541. eiter->len = cpu_to_be16(4 + alen);
  1542. size += 4 + alen;
  1543. ql_dbg(ql_dbg_disc, vha, 0x20a7,
  1544. "Model Name = %s.\n", eiter->a.model);
  1545. /* Model description. */
  1546. eiter = entries + size;
  1547. eiter->type = cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
  1548. snprintf(eiter->a.model_desc, sizeof(eiter->a.model_desc),
  1549. "%s", ha->model_desc);
  1550. alen = strlen(eiter->a.model_desc);
  1551. alen += 4 - (alen & 3);
  1552. eiter->len = cpu_to_be16(4 + alen);
  1553. size += 4 + alen;
  1554. ql_dbg(ql_dbg_disc, vha, 0x20a8,
  1555. "Model Desc = %s.\n", eiter->a.model_desc);
  1556. /* Hardware version. */
  1557. eiter = entries + size;
  1558. eiter->type = cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
  1559. if (!IS_FWI2_CAPABLE(ha)) {
  1560. snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
  1561. "HW:%s", ha->adapter_id);
  1562. } else if (qla2xxx_get_vpd_field(vha, "MN", eiter->a.hw_version,
  1563. sizeof(eiter->a.hw_version))) {
  1564. ;
  1565. } else if (qla2xxx_get_vpd_field(vha, "EC", eiter->a.hw_version,
  1566. sizeof(eiter->a.hw_version))) {
  1567. ;
  1568. } else {
  1569. snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
  1570. "HW:%s", ha->adapter_id);
  1571. }
  1572. alen = strlen(eiter->a.hw_version);
  1573. alen += 4 - (alen & 3);
  1574. eiter->len = cpu_to_be16(4 + alen);
  1575. size += 4 + alen;
  1576. ql_dbg(ql_dbg_disc, vha, 0x20a9,
  1577. "Hardware ver = %s.\n", eiter->a.hw_version);
  1578. /* Driver version. */
  1579. eiter = entries + size;
  1580. eiter->type = cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
  1581. snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version),
  1582. "%s", qla2x00_version_str);
  1583. alen = strlen(eiter->a.driver_version);
  1584. alen += 4 - (alen & 3);
  1585. eiter->len = cpu_to_be16(4 + alen);
  1586. size += 4 + alen;
  1587. ql_dbg(ql_dbg_disc, vha, 0x20aa,
  1588. "Driver ver = %s.\n", eiter->a.driver_version);
  1589. /* Option ROM version. */
  1590. eiter = entries + size;
  1591. eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
  1592. snprintf(eiter->a.orom_version, sizeof(eiter->a.orom_version),
  1593. "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
  1594. alen = strlen(eiter->a.orom_version);
  1595. alen += 4 - (alen & 3);
  1596. eiter->len = cpu_to_be16(4 + alen);
  1597. size += 4 + alen;
  1598. ql_dbg(ql_dbg_disc, vha , 0x20ab,
  1599. "Optrom version = %d.%02d.\n", eiter->a.orom_version[1],
  1600. eiter->a.orom_version[0]);
  1601. /* Firmware version */
  1602. eiter = entries + size;
  1603. eiter->type = cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
  1604. ha->isp_ops->fw_version_str(vha, eiter->a.fw_version,
  1605. sizeof(eiter->a.fw_version));
  1606. alen = strlen(eiter->a.fw_version);
  1607. alen += 4 - (alen & 3);
  1608. eiter->len = cpu_to_be16(4 + alen);
  1609. size += 4 + alen;
  1610. ql_dbg(ql_dbg_disc, vha, 0x20ac,
  1611. "Firmware vers = %s.\n", eiter->a.fw_version);
  1612. /* OS Name and Version */
  1613. eiter = entries + size;
  1614. eiter->type = cpu_to_be16(FDMI_HBA_OS_NAME_AND_VERSION);
  1615. p_sysid = utsname();
  1616. if (p_sysid) {
  1617. snprintf(eiter->a.os_version, sizeof(eiter->a.os_version),
  1618. "%s %s %s",
  1619. p_sysid->sysname, p_sysid->release, p_sysid->version);
  1620. } else {
  1621. snprintf(eiter->a.os_version, sizeof(eiter->a.os_version),
  1622. "%s %s", "Linux", fc_host_system_hostname(vha->host));
  1623. }
  1624. alen = strlen(eiter->a.os_version);
  1625. alen += 4 - (alen & 3);
  1626. eiter->len = cpu_to_be16(4 + alen);
  1627. size += 4 + alen;
  1628. ql_dbg(ql_dbg_disc, vha, 0x20ae,
  1629. "OS Name and Version = %s.\n", eiter->a.os_version);
  1630. /* MAX CT Payload Length */
  1631. eiter = entries + size;
  1632. eiter->type = cpu_to_be16(FDMI_HBA_MAXIMUM_CT_PAYLOAD_LENGTH);
  1633. eiter->a.max_ct_len = IS_FWI2_CAPABLE(ha) ?
  1634. le16_to_cpu(icb24->frame_payload_size) :
  1635. le16_to_cpu(ha->init_cb->frame_payload_size);
  1636. eiter->a.max_ct_len = cpu_to_be32(eiter->a.max_ct_len);
  1637. eiter->len = cpu_to_be16(4 + 4);
  1638. size += 4 + 4;
  1639. ql_dbg(ql_dbg_disc, vha, 0x20af,
  1640. "CT Payload Length = 0x%x.\n", eiter->a.max_ct_len);
  1641. /* Node Sybolic Name */
  1642. eiter = entries + size;
  1643. eiter->type = cpu_to_be16(FDMI_HBA_NODE_SYMBOLIC_NAME);
  1644. qla2x00_get_sym_node_name(vha, eiter->a.sym_name,
  1645. sizeof(eiter->a.sym_name));
  1646. alen = strlen(eiter->a.sym_name);
  1647. alen += 4 - (alen & 3);
  1648. eiter->len = cpu_to_be16(4 + alen);
  1649. size += 4 + alen;
  1650. ql_dbg(ql_dbg_disc, vha, 0x20b0,
  1651. "Symbolic Name = %s.\n", eiter->a.sym_name);
  1652. /* Vendor Id */
  1653. eiter = entries + size;
  1654. eiter->type = cpu_to_be16(FDMI_HBA_VENDOR_ID);
  1655. eiter->a.vendor_id = cpu_to_be32(0x1077);
  1656. eiter->len = cpu_to_be16(4 + 4);
  1657. size += 4 + 4;
  1658. ql_dbg(ql_dbg_disc, vha, 0x20b1,
  1659. "Vendor Id = %x.\n", eiter->a.vendor_id);
  1660. /* Num Ports */
  1661. eiter = entries + size;
  1662. eiter->type = cpu_to_be16(FDMI_HBA_NUM_PORTS);
  1663. eiter->a.num_ports = cpu_to_be32(1);
  1664. eiter->len = cpu_to_be16(4 + 4);
  1665. size += 4 + 4;
  1666. ql_dbg(ql_dbg_disc, vha, 0x20b2,
  1667. "Port Num = %x.\n", eiter->a.num_ports);
  1668. /* Fabric Name */
  1669. eiter = entries + size;
  1670. eiter->type = cpu_to_be16(FDMI_HBA_FABRIC_NAME);
  1671. memcpy(eiter->a.fabric_name, vha->fabric_node_name, WWN_SIZE);
  1672. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  1673. size += 4 + WWN_SIZE;
  1674. ql_dbg(ql_dbg_disc, vha, 0x20b3,
  1675. "Fabric Name = %016llx.\n", wwn_to_u64(eiter->a.fabric_name));
  1676. /* BIOS Version */
  1677. eiter = entries + size;
  1678. eiter->type = cpu_to_be16(FDMI_HBA_BOOT_BIOS_NAME);
  1679. snprintf(eiter->a.bios_name, sizeof(eiter->a.bios_name),
  1680. "BIOS %d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
  1681. alen = strlen(eiter->a.bios_name);
  1682. alen += 4 - (alen & 3);
  1683. eiter->len = cpu_to_be16(4 + alen);
  1684. size += 4 + alen;
  1685. ql_dbg(ql_dbg_disc, vha, 0x20b4,
  1686. "BIOS Name = %s\n", eiter->a.bios_name);
  1687. /* Vendor Identifier */
  1688. eiter = entries + size;
  1689. eiter->type = cpu_to_be16(FDMI_HBA_TYPE_VENDOR_IDENTIFIER);
  1690. snprintf(eiter->a.vendor_indentifer, sizeof(eiter->a.vendor_indentifer),
  1691. "%s", "QLGC");
  1692. alen = strlen(eiter->a.vendor_indentifer);
  1693. alen += 4 - (alen & 3);
  1694. eiter->len = cpu_to_be16(4 + alen);
  1695. size += 4 + alen;
  1696. ql_dbg(ql_dbg_disc, vha, 0x20b1,
  1697. "Vendor Identifier = %s.\n", eiter->a.vendor_indentifer);
  1698. /* Update MS request size. */
  1699. qla2x00_update_ms_fdmi_iocb(vha, size + 16);
  1700. ql_dbg(ql_dbg_disc, vha, 0x20b5,
  1701. "RHBA identifier = %016llx.\n",
  1702. wwn_to_u64(ct_req->req.rhba2.hba_identifier));
  1703. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20b6,
  1704. entries, size);
  1705. /* Execute MS IOCB */
  1706. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1707. sizeof(ms_iocb_entry_t));
  1708. if (rval != QLA_SUCCESS) {
  1709. /*EMPTY*/
  1710. ql_dbg(ql_dbg_disc, vha, 0x20b7,
  1711. "RHBA issue IOCB failed (%d).\n", rval);
  1712. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
  1713. QLA_SUCCESS) {
  1714. rval = QLA_FUNCTION_FAILED;
  1715. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  1716. ct_rsp->header.explanation_code ==
  1717. CT_EXPL_ALREADY_REGISTERED) {
  1718. ql_dbg(ql_dbg_disc, vha, 0x20b8,
  1719. "HBA already registered.\n");
  1720. rval = QLA_ALREADY_REGISTERED;
  1721. } else {
  1722. ql_dbg(ql_dbg_disc, vha, 0x2016,
  1723. "RHBA FDMI v2 failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
  1724. ct_rsp->header.reason_code,
  1725. ct_rsp->header.explanation_code);
  1726. }
  1727. } else {
  1728. ql_dbg(ql_dbg_disc, vha, 0x20b9,
  1729. "RHBA FDMI V2 exiting normally.\n");
  1730. }
  1731. return rval;
  1732. }
  1733. /**
  1734. * qla2x00_fdmi_dhba() -
  1735. * @ha: HA context
  1736. *
  1737. * Returns 0 on success.
  1738. */
  1739. static int
  1740. qla2x00_fdmi_dhba(scsi_qla_host_t *vha)
  1741. {
  1742. int rval;
  1743. struct qla_hw_data *ha = vha->hw;
  1744. ms_iocb_entry_t *ms_pkt;
  1745. struct ct_sns_req *ct_req;
  1746. struct ct_sns_rsp *ct_rsp;
  1747. /* Issue RPA */
  1748. /* Prepare common MS IOCB */
  1749. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, DHBA_REQ_SIZE,
  1750. DHBA_RSP_SIZE);
  1751. /* Prepare CT request */
  1752. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, DHBA_CMD, DHBA_RSP_SIZE);
  1753. ct_rsp = &ha->ct_sns->p.rsp;
  1754. /* Prepare FDMI command arguments -- portname. */
  1755. memcpy(ct_req->req.dhba.port_name, vha->port_name, WWN_SIZE);
  1756. ql_dbg(ql_dbg_disc, vha, 0x2036,
  1757. "DHBA portname = %8phN.\n", ct_req->req.dhba.port_name);
  1758. /* Execute MS IOCB */
  1759. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1760. sizeof(ms_iocb_entry_t));
  1761. if (rval != QLA_SUCCESS) {
  1762. /*EMPTY*/
  1763. ql_dbg(ql_dbg_disc, vha, 0x2037,
  1764. "DHBA issue IOCB failed (%d).\n", rval);
  1765. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "DHBA") !=
  1766. QLA_SUCCESS) {
  1767. rval = QLA_FUNCTION_FAILED;
  1768. } else {
  1769. ql_dbg(ql_dbg_disc, vha, 0x2038,
  1770. "DHBA exiting normally.\n");
  1771. }
  1772. return rval;
  1773. }
  1774. /**
  1775. * qla2x00_fdmiv2_rpa() -
  1776. * @ha: HA context
  1777. *
  1778. * Returns 0 on success.
  1779. */
  1780. static int
  1781. qla2x00_fdmiv2_rpa(scsi_qla_host_t *vha)
  1782. {
  1783. int rval, alen;
  1784. uint32_t size;
  1785. struct qla_hw_data *ha = vha->hw;
  1786. ms_iocb_entry_t *ms_pkt;
  1787. struct ct_sns_req *ct_req;
  1788. struct ct_sns_rsp *ct_rsp;
  1789. void *entries;
  1790. struct ct_fdmiv2_port_attr *eiter;
  1791. struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
  1792. struct new_utsname *p_sysid = NULL;
  1793. /* Issue RPA */
  1794. /* Prepare common MS IOCB */
  1795. /* Request size adjusted after CT preparation */
  1796. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
  1797. /* Prepare CT request */
  1798. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD, RPA_RSP_SIZE);
  1799. ct_rsp = &ha->ct_sns->p.rsp;
  1800. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1801. memcpy(ct_req->req.rpa2.port_name, vha->port_name, WWN_SIZE);
  1802. size = WWN_SIZE + 4;
  1803. /* Attributes */
  1804. ct_req->req.rpa2.attrs.count = cpu_to_be32(FDMIV2_PORT_ATTR_COUNT);
  1805. entries = ct_req->req.rpa2.port_name;
  1806. /* FC4 types. */
  1807. eiter = entries + size;
  1808. eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPES);
  1809. eiter->len = cpu_to_be16(4 + 32);
  1810. eiter->a.fc4_types[2] = 0x01;
  1811. size += 4 + 32;
  1812. ql_dbg(ql_dbg_disc, vha, 0x20ba,
  1813. "FC4_TYPES=%02x %02x.\n",
  1814. eiter->a.fc4_types[2],
  1815. eiter->a.fc4_types[1]);
  1816. /* Supported speed. */
  1817. eiter = entries + size;
  1818. eiter->type = cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
  1819. eiter->len = cpu_to_be16(4 + 4);
  1820. if (IS_CNA_CAPABLE(ha))
  1821. eiter->a.sup_speed = cpu_to_be32(
  1822. FDMI_PORT_SPEED_10GB);
  1823. else if (IS_QLA27XX(ha))
  1824. eiter->a.sup_speed = cpu_to_be32(
  1825. FDMI_PORT_SPEED_32GB|
  1826. FDMI_PORT_SPEED_16GB|
  1827. FDMI_PORT_SPEED_8GB);
  1828. else if (IS_QLA2031(ha))
  1829. eiter->a.sup_speed = cpu_to_be32(
  1830. FDMI_PORT_SPEED_16GB|
  1831. FDMI_PORT_SPEED_8GB|
  1832. FDMI_PORT_SPEED_4GB);
  1833. else if (IS_QLA25XX(ha))
  1834. eiter->a.sup_speed = cpu_to_be32(
  1835. FDMI_PORT_SPEED_8GB|
  1836. FDMI_PORT_SPEED_4GB|
  1837. FDMI_PORT_SPEED_2GB|
  1838. FDMI_PORT_SPEED_1GB);
  1839. else if (IS_QLA24XX_TYPE(ha))
  1840. eiter->a.sup_speed = cpu_to_be32(
  1841. FDMI_PORT_SPEED_4GB|
  1842. FDMI_PORT_SPEED_2GB|
  1843. FDMI_PORT_SPEED_1GB);
  1844. else if (IS_QLA23XX(ha))
  1845. eiter->a.sup_speed = cpu_to_be32(
  1846. FDMI_PORT_SPEED_2GB|
  1847. FDMI_PORT_SPEED_1GB);
  1848. else
  1849. eiter->a.sup_speed = cpu_to_be32(
  1850. FDMI_PORT_SPEED_1GB);
  1851. size += 4 + 4;
  1852. ql_dbg(ql_dbg_disc, vha, 0x20bb,
  1853. "Supported Port Speed = %x.\n", eiter->a.sup_speed);
  1854. /* Current speed. */
  1855. eiter = entries + size;
  1856. eiter->type = cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
  1857. eiter->len = cpu_to_be16(4 + 4);
  1858. switch (ha->link_data_rate) {
  1859. case PORT_SPEED_1GB:
  1860. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_1GB);
  1861. break;
  1862. case PORT_SPEED_2GB:
  1863. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_2GB);
  1864. break;
  1865. case PORT_SPEED_4GB:
  1866. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_4GB);
  1867. break;
  1868. case PORT_SPEED_8GB:
  1869. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_8GB);
  1870. break;
  1871. case PORT_SPEED_10GB:
  1872. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_10GB);
  1873. break;
  1874. case PORT_SPEED_16GB:
  1875. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_16GB);
  1876. break;
  1877. case PORT_SPEED_32GB:
  1878. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_32GB);
  1879. break;
  1880. default:
  1881. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
  1882. break;
  1883. }
  1884. size += 4 + 4;
  1885. ql_dbg(ql_dbg_disc, vha, 0x20bc,
  1886. "Current_Speed = %x.\n", eiter->a.cur_speed);
  1887. /* Max frame size. */
  1888. eiter = entries + size;
  1889. eiter->type = cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
  1890. eiter->len = cpu_to_be16(4 + 4);
  1891. eiter->a.max_frame_size = IS_FWI2_CAPABLE(ha) ?
  1892. le16_to_cpu(icb24->frame_payload_size):
  1893. le16_to_cpu(ha->init_cb->frame_payload_size);
  1894. eiter->a.max_frame_size = cpu_to_be32(eiter->a.max_frame_size);
  1895. size += 4 + 4;
  1896. ql_dbg(ql_dbg_disc, vha, 0x20bc,
  1897. "Max_Frame_Size = %x.\n", eiter->a.max_frame_size);
  1898. /* OS device name. */
  1899. eiter = entries + size;
  1900. eiter->type = cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
  1901. alen = strlen(QLA2XXX_DRIVER_NAME);
  1902. snprintf(eiter->a.os_dev_name, sizeof(eiter->a.os_dev_name),
  1903. "%s:host%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
  1904. alen += 4 - (alen & 3);
  1905. eiter->len = cpu_to_be16(4 + alen);
  1906. size += 4 + alen;
  1907. ql_dbg(ql_dbg_disc, vha, 0x20be,
  1908. "OS_Device_Name = %s.\n", eiter->a.os_dev_name);
  1909. /* Hostname. */
  1910. eiter = entries + size;
  1911. eiter->type = cpu_to_be16(FDMI_PORT_HOST_NAME);
  1912. p_sysid = utsname();
  1913. if (p_sysid) {
  1914. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  1915. "%s", p_sysid->nodename);
  1916. } else {
  1917. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  1918. "%s", fc_host_system_hostname(vha->host));
  1919. }
  1920. alen = strlen(eiter->a.host_name);
  1921. alen += 4 - (alen & 3);
  1922. eiter->len = cpu_to_be16(4 + alen);
  1923. size += 4 + alen;
  1924. ql_dbg(ql_dbg_disc, vha, 0x203d,
  1925. "HostName=%s.\n", eiter->a.host_name);
  1926. /* Node Name */
  1927. eiter = entries + size;
  1928. eiter->type = cpu_to_be16(FDMI_PORT_NODE_NAME);
  1929. memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
  1930. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  1931. size += 4 + WWN_SIZE;
  1932. ql_dbg(ql_dbg_disc, vha, 0x20c0,
  1933. "Node Name = %016llx.\n", wwn_to_u64(eiter->a.node_name));
  1934. /* Port Name */
  1935. eiter = entries + size;
  1936. eiter->type = cpu_to_be16(FDMI_PORT_NAME);
  1937. memcpy(eiter->a.port_name, vha->port_name, WWN_SIZE);
  1938. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  1939. size += 4 + WWN_SIZE;
  1940. ql_dbg(ql_dbg_disc, vha, 0x20c1,
  1941. "Port Name = %016llx.\n", wwn_to_u64(eiter->a.port_name));
  1942. /* Port Symbolic Name */
  1943. eiter = entries + size;
  1944. eiter->type = cpu_to_be16(FDMI_PORT_SYM_NAME);
  1945. qla2x00_get_sym_node_name(vha, eiter->a.port_sym_name,
  1946. sizeof(eiter->a.port_sym_name));
  1947. alen = strlen(eiter->a.port_sym_name);
  1948. alen += 4 - (alen & 3);
  1949. eiter->len = cpu_to_be16(4 + alen);
  1950. size += 4 + alen;
  1951. ql_dbg(ql_dbg_disc, vha, 0x20c2,
  1952. "port symbolic name = %s\n", eiter->a.port_sym_name);
  1953. /* Port Type */
  1954. eiter = entries + size;
  1955. eiter->type = cpu_to_be16(FDMI_PORT_TYPE);
  1956. eiter->a.port_type = cpu_to_be32(NS_NX_PORT_TYPE);
  1957. eiter->len = cpu_to_be16(4 + 4);
  1958. size += 4 + 4;
  1959. ql_dbg(ql_dbg_disc, vha, 0x20c3,
  1960. "Port Type = %x.\n", eiter->a.port_type);
  1961. /* Class of Service */
  1962. eiter = entries + size;
  1963. eiter->type = cpu_to_be16(FDMI_PORT_SUPP_COS);
  1964. eiter->a.port_supported_cos = cpu_to_be32(FC_CLASS_3);
  1965. eiter->len = cpu_to_be16(4 + 4);
  1966. size += 4 + 4;
  1967. ql_dbg(ql_dbg_disc, vha, 0x20c4,
  1968. "Supported COS = %08x\n", eiter->a.port_supported_cos);
  1969. /* Port Fabric Name */
  1970. eiter = entries + size;
  1971. eiter->type = cpu_to_be16(FDMI_PORT_FABRIC_NAME);
  1972. memcpy(eiter->a.fabric_name, vha->fabric_node_name, WWN_SIZE);
  1973. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  1974. size += 4 + WWN_SIZE;
  1975. ql_dbg(ql_dbg_disc, vha, 0x20c5,
  1976. "Fabric Name = %016llx.\n", wwn_to_u64(eiter->a.fabric_name));
  1977. /* FC4_type */
  1978. eiter = entries + size;
  1979. eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPE);
  1980. eiter->a.port_fc4_type[0] = 0;
  1981. eiter->a.port_fc4_type[1] = 0;
  1982. eiter->a.port_fc4_type[2] = 1;
  1983. eiter->a.port_fc4_type[3] = 0;
  1984. eiter->len = cpu_to_be16(4 + 32);
  1985. size += 4 + 32;
  1986. ql_dbg(ql_dbg_disc, vha, 0x20c6,
  1987. "Port Active FC4 Type = %02x %02x.\n",
  1988. eiter->a.port_fc4_type[2], eiter->a.port_fc4_type[1]);
  1989. /* Port State */
  1990. eiter = entries + size;
  1991. eiter->type = cpu_to_be16(FDMI_PORT_STATE);
  1992. eiter->a.port_state = cpu_to_be32(1);
  1993. eiter->len = cpu_to_be16(4 + 4);
  1994. size += 4 + 4;
  1995. ql_dbg(ql_dbg_disc, vha, 0x20c7,
  1996. "Port State = %x.\n", eiter->a.port_state);
  1997. /* Number of Ports */
  1998. eiter = entries + size;
  1999. eiter->type = cpu_to_be16(FDMI_PORT_COUNT);
  2000. eiter->a.num_ports = cpu_to_be32(1);
  2001. eiter->len = cpu_to_be16(4 + 4);
  2002. size += 4 + 4;
  2003. ql_dbg(ql_dbg_disc, vha, 0x20c8,
  2004. "Number of ports = %x.\n", eiter->a.num_ports);
  2005. /* Port Id */
  2006. eiter = entries + size;
  2007. eiter->type = cpu_to_be16(FDMI_PORT_ID);
  2008. eiter->a.port_id = cpu_to_be32(vha->d_id.b24);
  2009. eiter->len = cpu_to_be16(4 + 4);
  2010. size += 4 + 4;
  2011. ql_dbg(ql_dbg_disc, vha, 0x20c8,
  2012. "Port Id = %x.\n", eiter->a.port_id);
  2013. /* Update MS request size. */
  2014. qla2x00_update_ms_fdmi_iocb(vha, size + 16);
  2015. ql_dbg(ql_dbg_disc, vha, 0x203e,
  2016. "RPA portname= %8phN size=%d.\n", ct_req->req.rpa.port_name, size);
  2017. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20ca,
  2018. entries, size);
  2019. /* Execute MS IOCB */
  2020. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  2021. sizeof(ms_iocb_entry_t));
  2022. if (rval != QLA_SUCCESS) {
  2023. /*EMPTY*/
  2024. ql_dbg(ql_dbg_disc, vha, 0x20cb,
  2025. "RPA FDMI v2 issue IOCB failed (%d).\n", rval);
  2026. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
  2027. QLA_SUCCESS) {
  2028. rval = QLA_FUNCTION_FAILED;
  2029. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  2030. ct_rsp->header.explanation_code ==
  2031. CT_EXPL_ALREADY_REGISTERED) {
  2032. ql_dbg(ql_dbg_disc, vha, 0x20ce,
  2033. "RPA FDMI v2 already registered\n");
  2034. rval = QLA_ALREADY_REGISTERED;
  2035. } else {
  2036. ql_dbg(ql_dbg_disc, vha, 0x2020,
  2037. "RPA FDMI v2 failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
  2038. ct_rsp->header.reason_code,
  2039. ct_rsp->header.explanation_code);
  2040. }
  2041. } else {
  2042. ql_dbg(ql_dbg_disc, vha, 0x20cc,
  2043. "RPA FDMI V2 exiting normally.\n");
  2044. }
  2045. return rval;
  2046. }
  2047. /**
  2048. * qla2x00_fdmi_register() -
  2049. * @ha: HA context
  2050. *
  2051. * Returns 0 on success.
  2052. */
  2053. int
  2054. qla2x00_fdmi_register(scsi_qla_host_t *vha)
  2055. {
  2056. int rval = QLA_FUNCTION_FAILED;
  2057. struct qla_hw_data *ha = vha->hw;
  2058. if (IS_QLA2100(ha) || IS_QLA2200(ha) ||
  2059. IS_QLAFX00(ha))
  2060. return QLA_FUNCTION_FAILED;
  2061. rval = qla2x00_mgmt_svr_login(vha);
  2062. if (rval)
  2063. return rval;
  2064. rval = qla2x00_fdmiv2_rhba(vha);
  2065. if (rval) {
  2066. if (rval != QLA_ALREADY_REGISTERED)
  2067. goto try_fdmi;
  2068. rval = qla2x00_fdmi_dhba(vha);
  2069. if (rval)
  2070. goto try_fdmi;
  2071. rval = qla2x00_fdmiv2_rhba(vha);
  2072. if (rval)
  2073. goto try_fdmi;
  2074. }
  2075. rval = qla2x00_fdmiv2_rpa(vha);
  2076. if (rval)
  2077. goto try_fdmi;
  2078. goto out;
  2079. try_fdmi:
  2080. rval = qla2x00_fdmi_rhba(vha);
  2081. if (rval) {
  2082. if (rval != QLA_ALREADY_REGISTERED)
  2083. return rval;
  2084. rval = qla2x00_fdmi_dhba(vha);
  2085. if (rval)
  2086. return rval;
  2087. rval = qla2x00_fdmi_rhba(vha);
  2088. if (rval)
  2089. return rval;
  2090. }
  2091. rval = qla2x00_fdmi_rpa(vha);
  2092. out:
  2093. return rval;
  2094. }
  2095. /**
  2096. * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
  2097. * @ha: HA context
  2098. * @list: switch info entries to populate
  2099. *
  2100. * Returns 0 on success.
  2101. */
  2102. int
  2103. qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
  2104. {
  2105. int rval = QLA_SUCCESS;
  2106. uint16_t i;
  2107. struct qla_hw_data *ha = vha->hw;
  2108. ms_iocb_entry_t *ms_pkt;
  2109. struct ct_sns_req *ct_req;
  2110. struct ct_sns_rsp *ct_rsp;
  2111. if (!IS_IIDMA_CAPABLE(ha))
  2112. return QLA_FUNCTION_FAILED;
  2113. for (i = 0; i < ha->max_fibre_devices; i++) {
  2114. /* Issue GFPN_ID */
  2115. /* Prepare common MS IOCB */
  2116. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFPN_ID_REQ_SIZE,
  2117. GFPN_ID_RSP_SIZE);
  2118. /* Prepare CT request */
  2119. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFPN_ID_CMD,
  2120. GFPN_ID_RSP_SIZE);
  2121. ct_rsp = &ha->ct_sns->p.rsp;
  2122. /* Prepare CT arguments -- port_id */
  2123. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  2124. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  2125. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  2126. /* Execute MS IOCB */
  2127. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  2128. sizeof(ms_iocb_entry_t));
  2129. if (rval != QLA_SUCCESS) {
  2130. /*EMPTY*/
  2131. ql_dbg(ql_dbg_disc, vha, 0x2023,
  2132. "GFPN_ID issue IOCB failed (%d).\n", rval);
  2133. break;
  2134. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  2135. "GFPN_ID") != QLA_SUCCESS) {
  2136. rval = QLA_FUNCTION_FAILED;
  2137. break;
  2138. } else {
  2139. /* Save fabric portname */
  2140. memcpy(list[i].fabric_port_name,
  2141. ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
  2142. }
  2143. /* Last device exit. */
  2144. if (list[i].d_id.b.rsvd_1 != 0)
  2145. break;
  2146. }
  2147. return (rval);
  2148. }
  2149. static inline void *
  2150. qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *vha, uint32_t req_size,
  2151. uint32_t rsp_size)
  2152. {
  2153. struct ct_entry_24xx *ct_pkt;
  2154. struct qla_hw_data *ha = vha->hw;
  2155. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  2156. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  2157. ct_pkt->entry_type = CT_IOCB_TYPE;
  2158. ct_pkt->entry_count = 1;
  2159. ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
  2160. ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  2161. ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  2162. ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
  2163. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  2164. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  2165. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  2166. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  2167. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  2168. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  2169. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  2170. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  2171. ct_pkt->vp_index = vha->vp_idx;
  2172. return ct_pkt;
  2173. }
  2174. static inline struct ct_sns_req *
  2175. qla24xx_prep_ct_fm_req(struct ct_sns_pkt *p, uint16_t cmd,
  2176. uint16_t rsp_size)
  2177. {
  2178. memset(p, 0, sizeof(struct ct_sns_pkt));
  2179. p->p.req.header.revision = 0x01;
  2180. p->p.req.header.gs_type = 0xFA;
  2181. p->p.req.header.gs_subtype = 0x01;
  2182. p->p.req.command = cpu_to_be16(cmd);
  2183. p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  2184. return &p->p.req;
  2185. }
  2186. /**
  2187. * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
  2188. * @ha: HA context
  2189. * @list: switch info entries to populate
  2190. *
  2191. * Returns 0 on success.
  2192. */
  2193. int
  2194. qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list)
  2195. {
  2196. int rval;
  2197. uint16_t i;
  2198. struct qla_hw_data *ha = vha->hw;
  2199. ms_iocb_entry_t *ms_pkt;
  2200. struct ct_sns_req *ct_req;
  2201. struct ct_sns_rsp *ct_rsp;
  2202. if (!IS_IIDMA_CAPABLE(ha))
  2203. return QLA_FUNCTION_FAILED;
  2204. if (!ha->flags.gpsc_supported)
  2205. return QLA_FUNCTION_FAILED;
  2206. rval = qla2x00_mgmt_svr_login(vha);
  2207. if (rval)
  2208. return rval;
  2209. for (i = 0; i < ha->max_fibre_devices; i++) {
  2210. /* Issue GFPN_ID */
  2211. /* Prepare common MS IOCB */
  2212. ms_pkt = qla24xx_prep_ms_fm_iocb(vha, GPSC_REQ_SIZE,
  2213. GPSC_RSP_SIZE);
  2214. /* Prepare CT request */
  2215. ct_req = qla24xx_prep_ct_fm_req(ha->ct_sns, GPSC_CMD,
  2216. GPSC_RSP_SIZE);
  2217. ct_rsp = &ha->ct_sns->p.rsp;
  2218. /* Prepare CT arguments -- port_name */
  2219. memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
  2220. WWN_SIZE);
  2221. /* Execute MS IOCB */
  2222. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  2223. sizeof(ms_iocb_entry_t));
  2224. if (rval != QLA_SUCCESS) {
  2225. /*EMPTY*/
  2226. ql_dbg(ql_dbg_disc, vha, 0x2059,
  2227. "GPSC issue IOCB failed (%d).\n", rval);
  2228. } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  2229. "GPSC")) != QLA_SUCCESS) {
  2230. /* FM command unsupported? */
  2231. if (rval == QLA_INVALID_COMMAND &&
  2232. (ct_rsp->header.reason_code ==
  2233. CT_REASON_INVALID_COMMAND_CODE ||
  2234. ct_rsp->header.reason_code ==
  2235. CT_REASON_COMMAND_UNSUPPORTED)) {
  2236. ql_dbg(ql_dbg_disc, vha, 0x205a,
  2237. "GPSC command unsupported, disabling "
  2238. "query.\n");
  2239. ha->flags.gpsc_supported = 0;
  2240. rval = QLA_FUNCTION_FAILED;
  2241. break;
  2242. }
  2243. rval = QLA_FUNCTION_FAILED;
  2244. } else {
  2245. /* Save port-speed */
  2246. switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
  2247. case BIT_15:
  2248. list[i].fp_speed = PORT_SPEED_1GB;
  2249. break;
  2250. case BIT_14:
  2251. list[i].fp_speed = PORT_SPEED_2GB;
  2252. break;
  2253. case BIT_13:
  2254. list[i].fp_speed = PORT_SPEED_4GB;
  2255. break;
  2256. case BIT_12:
  2257. list[i].fp_speed = PORT_SPEED_10GB;
  2258. break;
  2259. case BIT_11:
  2260. list[i].fp_speed = PORT_SPEED_8GB;
  2261. break;
  2262. case BIT_10:
  2263. list[i].fp_speed = PORT_SPEED_16GB;
  2264. break;
  2265. case BIT_8:
  2266. list[i].fp_speed = PORT_SPEED_32GB;
  2267. break;
  2268. }
  2269. ql_dbg(ql_dbg_disc, vha, 0x205b,
  2270. "GPSC ext entry - fpn "
  2271. "%8phN speeds=%04x speed=%04x.\n",
  2272. list[i].fabric_port_name,
  2273. be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
  2274. be16_to_cpu(ct_rsp->rsp.gpsc.speed));
  2275. }
  2276. /* Last device exit. */
  2277. if (list[i].d_id.b.rsvd_1 != 0)
  2278. break;
  2279. }
  2280. return (rval);
  2281. }
  2282. /**
  2283. * qla2x00_gff_id() - SNS Get FC-4 Features (GFF_ID) query.
  2284. *
  2285. * @ha: HA context
  2286. * @list: switch info entries to populate
  2287. *
  2288. */
  2289. void
  2290. qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
  2291. {
  2292. int rval;
  2293. uint16_t i;
  2294. ms_iocb_entry_t *ms_pkt;
  2295. struct ct_sns_req *ct_req;
  2296. struct ct_sns_rsp *ct_rsp;
  2297. struct qla_hw_data *ha = vha->hw;
  2298. uint8_t fcp_scsi_features = 0;
  2299. for (i = 0; i < ha->max_fibre_devices; i++) {
  2300. /* Set default FC4 Type as UNKNOWN so the default is to
  2301. * Process this port */
  2302. list[i].fc4_type = FC4_TYPE_UNKNOWN;
  2303. /* Do not attempt GFF_ID if we are not FWI_2 capable */
  2304. if (!IS_FWI2_CAPABLE(ha))
  2305. continue;
  2306. /* Prepare common MS IOCB */
  2307. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFF_ID_REQ_SIZE,
  2308. GFF_ID_RSP_SIZE);
  2309. /* Prepare CT request */
  2310. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFF_ID_CMD,
  2311. GFF_ID_RSP_SIZE);
  2312. ct_rsp = &ha->ct_sns->p.rsp;
  2313. /* Prepare CT arguments -- port_id */
  2314. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  2315. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  2316. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  2317. /* Execute MS IOCB */
  2318. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  2319. sizeof(ms_iocb_entry_t));
  2320. if (rval != QLA_SUCCESS) {
  2321. ql_dbg(ql_dbg_disc, vha, 0x205c,
  2322. "GFF_ID issue IOCB failed (%d).\n", rval);
  2323. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  2324. "GFF_ID") != QLA_SUCCESS) {
  2325. ql_dbg(ql_dbg_disc, vha, 0x205d,
  2326. "GFF_ID IOCB status had a failure status code.\n");
  2327. } else {
  2328. fcp_scsi_features =
  2329. ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
  2330. fcp_scsi_features &= 0x0f;
  2331. if (fcp_scsi_features)
  2332. list[i].fc4_type = FC4_TYPE_FCP_SCSI;
  2333. else
  2334. list[i].fc4_type = FC4_TYPE_OTHER;
  2335. }
  2336. /* Last device exit. */
  2337. if (list[i].d_id.b.rsvd_1 != 0)
  2338. break;
  2339. }
  2340. }