qla_gs.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2005 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. static inline struct ct_sns_req *
  9. qla2x00_prep_ct_req(struct ct_sns_req *, uint16_t, uint16_t);
  10. static inline struct sns_cmd_pkt *
  11. qla2x00_prep_sns_cmd(scsi_qla_host_t *, uint16_t, uint16_t, uint16_t);
  12. static int qla2x00_sns_ga_nxt(scsi_qla_host_t *, fc_port_t *);
  13. static int qla2x00_sns_gid_pt(scsi_qla_host_t *, sw_info_t *);
  14. static int qla2x00_sns_gpn_id(scsi_qla_host_t *, sw_info_t *);
  15. static int qla2x00_sns_gnn_id(scsi_qla_host_t *, sw_info_t *);
  16. static int qla2x00_sns_rft_id(scsi_qla_host_t *);
  17. static int qla2x00_sns_rnn_id(scsi_qla_host_t *);
  18. /**
  19. * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query.
  20. * @ha: HA context
  21. * @req_size: request size in bytes
  22. * @rsp_size: response size in bytes
  23. *
  24. * Returns a pointer to the @ha's ms_iocb.
  25. */
  26. void *
  27. qla2x00_prep_ms_iocb(scsi_qla_host_t *ha, uint32_t req_size, uint32_t rsp_size)
  28. {
  29. ms_iocb_entry_t *ms_pkt;
  30. ms_pkt = ha->ms_iocb;
  31. memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
  32. ms_pkt->entry_type = MS_IOCB_TYPE;
  33. ms_pkt->entry_count = 1;
  34. SET_TARGET_ID(ha, ms_pkt->loop_id, SIMPLE_NAME_SERVER);
  35. ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
  36. ms_pkt->timeout = __constant_cpu_to_le16(25);
  37. ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  38. ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
  39. ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
  40. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  41. ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  42. ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  43. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  44. ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  45. ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  46. ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
  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 *ha, uint32_t req_size, uint32_t rsp_size)
  59. {
  60. struct ct_entry_24xx *ct_pkt;
  61. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  62. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  63. ct_pkt->entry_type = CT_IOCB_TYPE;
  64. ct_pkt->entry_count = 1;
  65. ct_pkt->nport_handle = __constant_cpu_to_le16(NPH_SNS);
  66. ct_pkt->timeout = __constant_cpu_to_le16(25);
  67. ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  68. ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
  69. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  70. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  71. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  72. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  73. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  74. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  75. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  76. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  77. return (ct_pkt);
  78. }
  79. /**
  80. * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
  81. * @ct_req: CT request buffer
  82. * @cmd: GS command
  83. * @rsp_size: response size in bytes
  84. *
  85. * Returns a pointer to the intitialized @ct_req.
  86. */
  87. static inline struct ct_sns_req *
  88. qla2x00_prep_ct_req(struct ct_sns_req *ct_req, uint16_t cmd, uint16_t rsp_size)
  89. {
  90. memset(ct_req, 0, sizeof(struct ct_sns_pkt));
  91. ct_req->header.revision = 0x01;
  92. ct_req->header.gs_type = 0xFC;
  93. ct_req->header.gs_subtype = 0x02;
  94. ct_req->command = cpu_to_be16(cmd);
  95. ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  96. return (ct_req);
  97. }
  98. static int
  99. qla2x00_chk_ms_status(scsi_qla_host_t *ha, ms_iocb_entry_t *ms_pkt,
  100. struct ct_sns_rsp *ct_rsp, const char *routine)
  101. {
  102. int rval;
  103. uint16_t comp_status;
  104. rval = QLA_FUNCTION_FAILED;
  105. if (ms_pkt->entry_status != 0) {
  106. DEBUG2_3(printk("scsi(%ld): %s failed, error status (%x).\n",
  107. ha->host_no, routine, ms_pkt->entry_status));
  108. } else {
  109. if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
  110. comp_status = le16_to_cpu(
  111. ((struct ct_entry_24xx *)ms_pkt)->comp_status);
  112. else
  113. comp_status = le16_to_cpu(ms_pkt->status);
  114. switch (comp_status) {
  115. case CS_COMPLETE:
  116. case CS_DATA_UNDERRUN:
  117. case CS_DATA_OVERRUN: /* Overrun? */
  118. if (ct_rsp->header.response !=
  119. __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
  120. DEBUG2_3(printk("scsi(%ld): %s failed, "
  121. "rejected request:\n", ha->host_no,
  122. routine));
  123. DEBUG2_3(qla2x00_dump_buffer(
  124. (uint8_t *)&ct_rsp->header,
  125. sizeof(struct ct_rsp_hdr)));
  126. rval = QLA_INVALID_COMMAND;
  127. } else
  128. rval = QLA_SUCCESS;
  129. break;
  130. default:
  131. DEBUG2_3(printk("scsi(%ld): %s failed, completion "
  132. "status (%x).\n", ha->host_no, routine,
  133. comp_status));
  134. break;
  135. }
  136. }
  137. return rval;
  138. }
  139. /**
  140. * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
  141. * @ha: HA context
  142. * @fcport: fcport entry to updated
  143. *
  144. * Returns 0 on success.
  145. */
  146. int
  147. qla2x00_ga_nxt(scsi_qla_host_t *ha, fc_port_t *fcport)
  148. {
  149. int rval;
  150. ms_iocb_entry_t *ms_pkt;
  151. struct ct_sns_req *ct_req;
  152. struct ct_sns_rsp *ct_rsp;
  153. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  154. return (qla2x00_sns_ga_nxt(ha, fcport));
  155. }
  156. /* Issue GA_NXT */
  157. /* Prepare common MS IOCB */
  158. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GA_NXT_REQ_SIZE, GA_NXT_RSP_SIZE);
  159. /* Prepare CT request */
  160. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GA_NXT_CMD,
  161. GA_NXT_RSP_SIZE);
  162. ct_rsp = &ha->ct_sns->p.rsp;
  163. /* Prepare CT arguments -- port_id */
  164. ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
  165. ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
  166. ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
  167. /* Execute MS IOCB */
  168. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  169. sizeof(ms_iocb_entry_t));
  170. if (rval != QLA_SUCCESS) {
  171. /*EMPTY*/
  172. DEBUG2_3(printk("scsi(%ld): GA_NXT issue IOCB failed (%d).\n",
  173. ha->host_no, rval));
  174. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "GA_NXT") !=
  175. QLA_SUCCESS) {
  176. rval = QLA_FUNCTION_FAILED;
  177. } else {
  178. /* Populate fc_port_t entry. */
  179. fcport->d_id.b.domain = ct_rsp->rsp.ga_nxt.port_id[0];
  180. fcport->d_id.b.area = ct_rsp->rsp.ga_nxt.port_id[1];
  181. fcport->d_id.b.al_pa = ct_rsp->rsp.ga_nxt.port_id[2];
  182. memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name,
  183. WWN_SIZE);
  184. memcpy(fcport->port_name, ct_rsp->rsp.ga_nxt.port_name,
  185. WWN_SIZE);
  186. if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE &&
  187. ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE)
  188. fcport->d_id.b.domain = 0xf0;
  189. DEBUG2_3(printk("scsi(%ld): GA_NXT entry - "
  190. "nn %02x%02x%02x%02x%02x%02x%02x%02x "
  191. "pn %02x%02x%02x%02x%02x%02x%02x%02x "
  192. "portid=%02x%02x%02x.\n",
  193. ha->host_no,
  194. fcport->node_name[0], fcport->node_name[1],
  195. fcport->node_name[2], fcport->node_name[3],
  196. fcport->node_name[4], fcport->node_name[5],
  197. fcport->node_name[6], fcport->node_name[7],
  198. fcport->port_name[0], fcport->port_name[1],
  199. fcport->port_name[2], fcport->port_name[3],
  200. fcport->port_name[4], fcport->port_name[5],
  201. fcport->port_name[6], fcport->port_name[7],
  202. fcport->d_id.b.domain, fcport->d_id.b.area,
  203. fcport->d_id.b.al_pa));
  204. }
  205. return (rval);
  206. }
  207. /**
  208. * qla2x00_gid_pt() - SNS scan for fabric devices via GID_PT command.
  209. * @ha: HA context
  210. * @list: switch info entries to populate
  211. *
  212. * NOTE: Non-Nx_Ports are not requested.
  213. *
  214. * Returns 0 on success.
  215. */
  216. int
  217. qla2x00_gid_pt(scsi_qla_host_t *ha, sw_info_t *list)
  218. {
  219. int rval;
  220. uint16_t i;
  221. ms_iocb_entry_t *ms_pkt;
  222. struct ct_sns_req *ct_req;
  223. struct ct_sns_rsp *ct_rsp;
  224. struct ct_sns_gid_pt_data *gid_data;
  225. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  226. return (qla2x00_sns_gid_pt(ha, list));
  227. }
  228. gid_data = NULL;
  229. /* Issue GID_PT */
  230. /* Prepare common MS IOCB */
  231. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GID_PT_REQ_SIZE, GID_PT_RSP_SIZE);
  232. /* Prepare CT request */
  233. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GID_PT_CMD,
  234. GID_PT_RSP_SIZE);
  235. ct_rsp = &ha->ct_sns->p.rsp;
  236. /* Prepare CT arguments -- port_type */
  237. ct_req->req.gid_pt.port_type = NS_NX_PORT_TYPE;
  238. /* Execute MS IOCB */
  239. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  240. sizeof(ms_iocb_entry_t));
  241. if (rval != QLA_SUCCESS) {
  242. /*EMPTY*/
  243. DEBUG2_3(printk("scsi(%ld): GID_PT issue IOCB failed (%d).\n",
  244. ha->host_no, rval));
  245. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "GID_PT") !=
  246. QLA_SUCCESS) {
  247. rval = QLA_FUNCTION_FAILED;
  248. } else {
  249. /* Set port IDs in switch info list. */
  250. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  251. gid_data = &ct_rsp->rsp.gid_pt.entries[i];
  252. list[i].d_id.b.domain = gid_data->port_id[0];
  253. list[i].d_id.b.area = gid_data->port_id[1];
  254. list[i].d_id.b.al_pa = gid_data->port_id[2];
  255. /* Last one exit. */
  256. if (gid_data->control_byte & BIT_7) {
  257. list[i].d_id.b.rsvd_1 = gid_data->control_byte;
  258. break;
  259. }
  260. }
  261. /*
  262. * If we've used all available slots, then the switch is
  263. * reporting back more devices than we can handle with this
  264. * single call. Return a failed status, and let GA_NXT handle
  265. * the overload.
  266. */
  267. if (i == MAX_FIBRE_DEVICES)
  268. rval = QLA_FUNCTION_FAILED;
  269. }
  270. return (rval);
  271. }
  272. /**
  273. * qla2x00_gpn_id() - SNS Get Port Name (GPN_ID) query.
  274. * @ha: HA context
  275. * @list: switch info entries to populate
  276. *
  277. * Returns 0 on success.
  278. */
  279. int
  280. qla2x00_gpn_id(scsi_qla_host_t *ha, sw_info_t *list)
  281. {
  282. int rval;
  283. uint16_t i;
  284. ms_iocb_entry_t *ms_pkt;
  285. struct ct_sns_req *ct_req;
  286. struct ct_sns_rsp *ct_rsp;
  287. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  288. return (qla2x00_sns_gpn_id(ha, list));
  289. }
  290. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  291. /* Issue GPN_ID */
  292. /* Prepare common MS IOCB */
  293. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GPN_ID_REQ_SIZE,
  294. GPN_ID_RSP_SIZE);
  295. /* Prepare CT request */
  296. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GPN_ID_CMD,
  297. GPN_ID_RSP_SIZE);
  298. ct_rsp = &ha->ct_sns->p.rsp;
  299. /* Prepare CT arguments -- port_id */
  300. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  301. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  302. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  303. /* Execute MS IOCB */
  304. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  305. sizeof(ms_iocb_entry_t));
  306. if (rval != QLA_SUCCESS) {
  307. /*EMPTY*/
  308. DEBUG2_3(printk("scsi(%ld): GPN_ID issue IOCB failed "
  309. "(%d).\n", ha->host_no, rval));
  310. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
  311. "GPN_ID") != QLA_SUCCESS) {
  312. rval = QLA_FUNCTION_FAILED;
  313. } else {
  314. /* Save portname */
  315. memcpy(list[i].port_name,
  316. ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
  317. }
  318. /* Last device exit. */
  319. if (list[i].d_id.b.rsvd_1 != 0)
  320. break;
  321. }
  322. return (rval);
  323. }
  324. /**
  325. * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query.
  326. * @ha: HA context
  327. * @list: switch info entries to populate
  328. *
  329. * Returns 0 on success.
  330. */
  331. int
  332. qla2x00_gnn_id(scsi_qla_host_t *ha, sw_info_t *list)
  333. {
  334. int rval;
  335. uint16_t i;
  336. ms_iocb_entry_t *ms_pkt;
  337. struct ct_sns_req *ct_req;
  338. struct ct_sns_rsp *ct_rsp;
  339. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  340. return (qla2x00_sns_gnn_id(ha, list));
  341. }
  342. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  343. /* Issue GNN_ID */
  344. /* Prepare common MS IOCB */
  345. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GNN_ID_REQ_SIZE,
  346. GNN_ID_RSP_SIZE);
  347. /* Prepare CT request */
  348. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GNN_ID_CMD,
  349. GNN_ID_RSP_SIZE);
  350. ct_rsp = &ha->ct_sns->p.rsp;
  351. /* Prepare CT arguments -- port_id */
  352. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  353. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  354. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  355. /* Execute MS IOCB */
  356. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  357. sizeof(ms_iocb_entry_t));
  358. if (rval != QLA_SUCCESS) {
  359. /*EMPTY*/
  360. DEBUG2_3(printk("scsi(%ld): GNN_ID issue IOCB failed "
  361. "(%d).\n", ha->host_no, rval));
  362. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
  363. "GNN_ID") != QLA_SUCCESS) {
  364. rval = QLA_FUNCTION_FAILED;
  365. } else {
  366. /* Save nodename */
  367. memcpy(list[i].node_name,
  368. ct_rsp->rsp.gnn_id.node_name, WWN_SIZE);
  369. DEBUG2_3(printk("scsi(%ld): GID_PT entry - "
  370. "nn %02x%02x%02x%02x%02x%02x%02x%02x "
  371. "pn %02x%02x%02x%02x%02x%02x%02x%02x "
  372. "portid=%02x%02x%02x.\n",
  373. ha->host_no,
  374. list[i].node_name[0], list[i].node_name[1],
  375. list[i].node_name[2], list[i].node_name[3],
  376. list[i].node_name[4], list[i].node_name[5],
  377. list[i].node_name[6], list[i].node_name[7],
  378. list[i].port_name[0], list[i].port_name[1],
  379. list[i].port_name[2], list[i].port_name[3],
  380. list[i].port_name[4], list[i].port_name[5],
  381. list[i].port_name[6], list[i].port_name[7],
  382. list[i].d_id.b.domain, list[i].d_id.b.area,
  383. list[i].d_id.b.al_pa));
  384. }
  385. /* Last device exit. */
  386. if (list[i].d_id.b.rsvd_1 != 0)
  387. break;
  388. }
  389. return (rval);
  390. }
  391. /**
  392. * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
  393. * @ha: HA context
  394. *
  395. * Returns 0 on success.
  396. */
  397. int
  398. qla2x00_rft_id(scsi_qla_host_t *ha)
  399. {
  400. int rval;
  401. ms_iocb_entry_t *ms_pkt;
  402. struct ct_sns_req *ct_req;
  403. struct ct_sns_rsp *ct_rsp;
  404. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  405. return (qla2x00_sns_rft_id(ha));
  406. }
  407. /* Issue RFT_ID */
  408. /* Prepare common MS IOCB */
  409. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, RFT_ID_REQ_SIZE, RFT_ID_RSP_SIZE);
  410. /* Prepare CT request */
  411. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RFT_ID_CMD,
  412. RFT_ID_RSP_SIZE);
  413. ct_rsp = &ha->ct_sns->p.rsp;
  414. /* Prepare CT arguments -- port_id, FC-4 types */
  415. ct_req->req.rft_id.port_id[0] = ha->d_id.b.domain;
  416. ct_req->req.rft_id.port_id[1] = ha->d_id.b.area;
  417. ct_req->req.rft_id.port_id[2] = ha->d_id.b.al_pa;
  418. ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */
  419. /* Execute MS IOCB */
  420. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  421. sizeof(ms_iocb_entry_t));
  422. if (rval != QLA_SUCCESS) {
  423. /*EMPTY*/
  424. DEBUG2_3(printk("scsi(%ld): RFT_ID issue IOCB failed (%d).\n",
  425. ha->host_no, rval));
  426. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RFT_ID") !=
  427. QLA_SUCCESS) {
  428. rval = QLA_FUNCTION_FAILED;
  429. } else {
  430. DEBUG2(printk("scsi(%ld): RFT_ID exiting normally.\n",
  431. ha->host_no));
  432. }
  433. return (rval);
  434. }
  435. /**
  436. * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA.
  437. * @ha: HA context
  438. *
  439. * Returns 0 on success.
  440. */
  441. int
  442. qla2x00_rff_id(scsi_qla_host_t *ha)
  443. {
  444. int rval;
  445. ms_iocb_entry_t *ms_pkt;
  446. struct ct_sns_req *ct_req;
  447. struct ct_sns_rsp *ct_rsp;
  448. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  449. DEBUG2(printk("scsi(%ld): RFF_ID call unsupported on "
  450. "ISP2100/ISP2200.\n", ha->host_no));
  451. return (QLA_SUCCESS);
  452. }
  453. /* Issue RFF_ID */
  454. /* Prepare common MS IOCB */
  455. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, RFF_ID_REQ_SIZE, RFF_ID_RSP_SIZE);
  456. /* Prepare CT request */
  457. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RFF_ID_CMD,
  458. RFF_ID_RSP_SIZE);
  459. ct_rsp = &ha->ct_sns->p.rsp;
  460. /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
  461. ct_req->req.rff_id.port_id[0] = ha->d_id.b.domain;
  462. ct_req->req.rff_id.port_id[1] = ha->d_id.b.area;
  463. ct_req->req.rff_id.port_id[2] = ha->d_id.b.al_pa;
  464. ct_req->req.rff_id.fc4_feature = BIT_1;
  465. ct_req->req.rff_id.fc4_type = 0x08; /* SCSI - FCP */
  466. /* Execute MS IOCB */
  467. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  468. sizeof(ms_iocb_entry_t));
  469. if (rval != QLA_SUCCESS) {
  470. /*EMPTY*/
  471. DEBUG2_3(printk("scsi(%ld): RFF_ID issue IOCB failed (%d).\n",
  472. ha->host_no, rval));
  473. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RFF_ID") !=
  474. QLA_SUCCESS) {
  475. rval = QLA_FUNCTION_FAILED;
  476. } else {
  477. DEBUG2(printk("scsi(%ld): RFF_ID exiting normally.\n",
  478. ha->host_no));
  479. }
  480. return (rval);
  481. }
  482. /**
  483. * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
  484. * @ha: HA context
  485. *
  486. * Returns 0 on success.
  487. */
  488. int
  489. qla2x00_rnn_id(scsi_qla_host_t *ha)
  490. {
  491. int rval;
  492. ms_iocb_entry_t *ms_pkt;
  493. struct ct_sns_req *ct_req;
  494. struct ct_sns_rsp *ct_rsp;
  495. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  496. return (qla2x00_sns_rnn_id(ha));
  497. }
  498. /* Issue RNN_ID */
  499. /* Prepare common MS IOCB */
  500. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, RNN_ID_REQ_SIZE, RNN_ID_RSP_SIZE);
  501. /* Prepare CT request */
  502. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RNN_ID_CMD,
  503. RNN_ID_RSP_SIZE);
  504. ct_rsp = &ha->ct_sns->p.rsp;
  505. /* Prepare CT arguments -- port_id, node_name */
  506. ct_req->req.rnn_id.port_id[0] = ha->d_id.b.domain;
  507. ct_req->req.rnn_id.port_id[1] = ha->d_id.b.area;
  508. ct_req->req.rnn_id.port_id[2] = ha->d_id.b.al_pa;
  509. memcpy(ct_req->req.rnn_id.node_name, ha->node_name, WWN_SIZE);
  510. /* Execute MS IOCB */
  511. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  512. sizeof(ms_iocb_entry_t));
  513. if (rval != QLA_SUCCESS) {
  514. /*EMPTY*/
  515. DEBUG2_3(printk("scsi(%ld): RNN_ID issue IOCB failed (%d).\n",
  516. ha->host_no, rval));
  517. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RNN_ID") !=
  518. QLA_SUCCESS) {
  519. rval = QLA_FUNCTION_FAILED;
  520. } else {
  521. DEBUG2(printk("scsi(%ld): RNN_ID exiting normally.\n",
  522. ha->host_no));
  523. }
  524. return (rval);
  525. }
  526. void
  527. qla2x00_get_sym_node_name(scsi_qla_host_t *ha, uint8_t *snn)
  528. {
  529. sprintf(snn, "%s FW:v%d.%02d.%02d DVR:v%s",ha->model_number,
  530. ha->fw_major_version, ha->fw_minor_version,
  531. ha->fw_subminor_version, qla2x00_version_str);
  532. }
  533. /**
  534. * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
  535. * @ha: HA context
  536. *
  537. * Returns 0 on success.
  538. */
  539. int
  540. qla2x00_rsnn_nn(scsi_qla_host_t *ha)
  541. {
  542. int rval;
  543. ms_iocb_entry_t *ms_pkt;
  544. struct ct_sns_req *ct_req;
  545. struct ct_sns_rsp *ct_rsp;
  546. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  547. DEBUG2(printk("scsi(%ld): RSNN_ID call unsupported on "
  548. "ISP2100/ISP2200.\n", ha->host_no));
  549. return (QLA_SUCCESS);
  550. }
  551. /* Issue RSNN_NN */
  552. /* Prepare common MS IOCB */
  553. /* Request size adjusted after CT preparation */
  554. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, 0, RSNN_NN_RSP_SIZE);
  555. /* Prepare CT request */
  556. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RSNN_NN_CMD,
  557. RSNN_NN_RSP_SIZE);
  558. ct_rsp = &ha->ct_sns->p.rsp;
  559. /* Prepare CT arguments -- node_name, symbolic node_name, size */
  560. memcpy(ct_req->req.rsnn_nn.node_name, ha->node_name, WWN_SIZE);
  561. /* Prepare the Symbolic Node Name */
  562. qla2x00_get_sym_node_name(ha, ct_req->req.rsnn_nn.sym_node_name);
  563. /* Calculate SNN length */
  564. ct_req->req.rsnn_nn.name_len =
  565. (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name);
  566. /* Update MS IOCB request */
  567. ms_pkt->req_bytecount =
  568. cpu_to_le32(24 + 1 + ct_req->req.rsnn_nn.name_len);
  569. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  570. /* Execute MS IOCB */
  571. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  572. sizeof(ms_iocb_entry_t));
  573. if (rval != QLA_SUCCESS) {
  574. /*EMPTY*/
  575. DEBUG2_3(printk("scsi(%ld): RSNN_NN issue IOCB failed (%d).\n",
  576. ha->host_no, rval));
  577. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RSNN_NN") !=
  578. QLA_SUCCESS) {
  579. rval = QLA_FUNCTION_FAILED;
  580. } else {
  581. DEBUG2(printk("scsi(%ld): RSNN_NN exiting normally.\n",
  582. ha->host_no));
  583. }
  584. return (rval);
  585. }
  586. /**
  587. * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query.
  588. * @ha: HA context
  589. * @cmd: GS command
  590. * @scmd_len: Subcommand length
  591. * @data_size: response size in bytes
  592. *
  593. * Returns a pointer to the @ha's sns_cmd.
  594. */
  595. static inline struct sns_cmd_pkt *
  596. qla2x00_prep_sns_cmd(scsi_qla_host_t *ha, uint16_t cmd, uint16_t scmd_len,
  597. uint16_t data_size)
  598. {
  599. uint16_t wc;
  600. struct sns_cmd_pkt *sns_cmd;
  601. sns_cmd = ha->sns_cmd;
  602. memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt));
  603. wc = data_size / 2; /* Size in 16bit words. */
  604. sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc);
  605. sns_cmd->p.cmd.buffer_address[0] = cpu_to_le32(LSD(ha->sns_cmd_dma));
  606. sns_cmd->p.cmd.buffer_address[1] = cpu_to_le32(MSD(ha->sns_cmd_dma));
  607. sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len);
  608. sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd);
  609. wc = (data_size - 16) / 4; /* Size in 32bit words. */
  610. sns_cmd->p.cmd.size = cpu_to_le16(wc);
  611. return (sns_cmd);
  612. }
  613. /**
  614. * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
  615. * @ha: HA context
  616. * @fcport: fcport entry to updated
  617. *
  618. * This command uses the old Exectute SNS Command mailbox routine.
  619. *
  620. * Returns 0 on success.
  621. */
  622. static int
  623. qla2x00_sns_ga_nxt(scsi_qla_host_t *ha, fc_port_t *fcport)
  624. {
  625. int rval;
  626. struct sns_cmd_pkt *sns_cmd;
  627. /* Issue GA_NXT. */
  628. /* Prepare SNS command request. */
  629. sns_cmd = qla2x00_prep_sns_cmd(ha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN,
  630. GA_NXT_SNS_DATA_SIZE);
  631. /* Prepare SNS command arguments -- port_id. */
  632. sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa;
  633. sns_cmd->p.cmd.param[1] = fcport->d_id.b.area;
  634. sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain;
  635. /* Execute SNS command. */
  636. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2,
  637. sizeof(struct sns_cmd_pkt));
  638. if (rval != QLA_SUCCESS) {
  639. /*EMPTY*/
  640. DEBUG2_3(printk("scsi(%ld): GA_NXT Send SNS failed (%d).\n",
  641. ha->host_no, rval));
  642. } else if (sns_cmd->p.gan_data[8] != 0x80 ||
  643. sns_cmd->p.gan_data[9] != 0x02) {
  644. DEBUG2_3(printk("scsi(%ld): GA_NXT failed, rejected request, "
  645. "ga_nxt_rsp:\n", ha->host_no));
  646. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gan_data, 16));
  647. rval = QLA_FUNCTION_FAILED;
  648. } else {
  649. /* Populate fc_port_t entry. */
  650. fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
  651. fcport->d_id.b.area = sns_cmd->p.gan_data[18];
  652. fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
  653. memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
  654. memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
  655. if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
  656. sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
  657. fcport->d_id.b.domain = 0xf0;
  658. DEBUG2_3(printk("scsi(%ld): GA_NXT entry - "
  659. "nn %02x%02x%02x%02x%02x%02x%02x%02x "
  660. "pn %02x%02x%02x%02x%02x%02x%02x%02x "
  661. "portid=%02x%02x%02x.\n",
  662. ha->host_no,
  663. fcport->node_name[0], fcport->node_name[1],
  664. fcport->node_name[2], fcport->node_name[3],
  665. fcport->node_name[4], fcport->node_name[5],
  666. fcport->node_name[6], fcport->node_name[7],
  667. fcport->port_name[0], fcport->port_name[1],
  668. fcport->port_name[2], fcport->port_name[3],
  669. fcport->port_name[4], fcport->port_name[5],
  670. fcport->port_name[6], fcport->port_name[7],
  671. fcport->d_id.b.domain, fcport->d_id.b.area,
  672. fcport->d_id.b.al_pa));
  673. }
  674. return (rval);
  675. }
  676. /**
  677. * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
  678. * @ha: HA context
  679. * @list: switch info entries to populate
  680. *
  681. * This command uses the old Exectute SNS Command mailbox routine.
  682. *
  683. * NOTE: Non-Nx_Ports are not requested.
  684. *
  685. * Returns 0 on success.
  686. */
  687. static int
  688. qla2x00_sns_gid_pt(scsi_qla_host_t *ha, sw_info_t *list)
  689. {
  690. int rval;
  691. uint16_t i;
  692. uint8_t *entry;
  693. struct sns_cmd_pkt *sns_cmd;
  694. /* Issue GID_PT. */
  695. /* Prepare SNS command request. */
  696. sns_cmd = qla2x00_prep_sns_cmd(ha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
  697. GID_PT_SNS_DATA_SIZE);
  698. /* Prepare SNS command arguments -- port_type. */
  699. sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
  700. /* Execute SNS command. */
  701. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
  702. sizeof(struct sns_cmd_pkt));
  703. if (rval != QLA_SUCCESS) {
  704. /*EMPTY*/
  705. DEBUG2_3(printk("scsi(%ld): GID_PT Send SNS failed (%d).\n",
  706. ha->host_no, rval));
  707. } else if (sns_cmd->p.gid_data[8] != 0x80 ||
  708. sns_cmd->p.gid_data[9] != 0x02) {
  709. DEBUG2_3(printk("scsi(%ld): GID_PT failed, rejected request, "
  710. "gid_rsp:\n", ha->host_no));
  711. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gid_data, 16));
  712. rval = QLA_FUNCTION_FAILED;
  713. } else {
  714. /* Set port IDs in switch info list. */
  715. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  716. entry = &sns_cmd->p.gid_data[(i * 4) + 16];
  717. list[i].d_id.b.domain = entry[1];
  718. list[i].d_id.b.area = entry[2];
  719. list[i].d_id.b.al_pa = entry[3];
  720. /* Last one exit. */
  721. if (entry[0] & BIT_7) {
  722. list[i].d_id.b.rsvd_1 = entry[0];
  723. break;
  724. }
  725. }
  726. /*
  727. * If we've used all available slots, then the switch is
  728. * reporting back more devices that we can handle with this
  729. * single call. Return a failed status, and let GA_NXT handle
  730. * the overload.
  731. */
  732. if (i == MAX_FIBRE_DEVICES)
  733. rval = QLA_FUNCTION_FAILED;
  734. }
  735. return (rval);
  736. }
  737. /**
  738. * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
  739. * @ha: HA context
  740. * @list: switch info entries to populate
  741. *
  742. * This command uses the old Exectute SNS Command mailbox routine.
  743. *
  744. * Returns 0 on success.
  745. */
  746. static int
  747. qla2x00_sns_gpn_id(scsi_qla_host_t *ha, sw_info_t *list)
  748. {
  749. int rval;
  750. uint16_t i;
  751. struct sns_cmd_pkt *sns_cmd;
  752. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  753. /* Issue GPN_ID */
  754. /* Prepare SNS command request. */
  755. sns_cmd = qla2x00_prep_sns_cmd(ha, GPN_ID_CMD,
  756. GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
  757. /* Prepare SNS command arguments -- port_id. */
  758. sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
  759. sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
  760. sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
  761. /* Execute SNS command. */
  762. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma,
  763. GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
  764. if (rval != QLA_SUCCESS) {
  765. /*EMPTY*/
  766. DEBUG2_3(printk("scsi(%ld): GPN_ID Send SNS failed "
  767. "(%d).\n", ha->host_no, rval));
  768. } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
  769. sns_cmd->p.gpn_data[9] != 0x02) {
  770. DEBUG2_3(printk("scsi(%ld): GPN_ID failed, rejected "
  771. "request, gpn_rsp:\n", ha->host_no));
  772. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gpn_data, 16));
  773. rval = QLA_FUNCTION_FAILED;
  774. } else {
  775. /* Save portname */
  776. memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
  777. WWN_SIZE);
  778. }
  779. /* Last device exit. */
  780. if (list[i].d_id.b.rsvd_1 != 0)
  781. break;
  782. }
  783. return (rval);
  784. }
  785. /**
  786. * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
  787. * @ha: HA context
  788. * @list: switch info entries to populate
  789. *
  790. * This command uses the old Exectute SNS Command mailbox routine.
  791. *
  792. * Returns 0 on success.
  793. */
  794. static int
  795. qla2x00_sns_gnn_id(scsi_qla_host_t *ha, sw_info_t *list)
  796. {
  797. int rval;
  798. uint16_t i;
  799. struct sns_cmd_pkt *sns_cmd;
  800. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  801. /* Issue GNN_ID */
  802. /* Prepare SNS command request. */
  803. sns_cmd = qla2x00_prep_sns_cmd(ha, GNN_ID_CMD,
  804. GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
  805. /* Prepare SNS command arguments -- port_id. */
  806. sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
  807. sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
  808. sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
  809. /* Execute SNS command. */
  810. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma,
  811. GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
  812. if (rval != QLA_SUCCESS) {
  813. /*EMPTY*/
  814. DEBUG2_3(printk("scsi(%ld): GNN_ID Send SNS failed "
  815. "(%d).\n", ha->host_no, rval));
  816. } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
  817. sns_cmd->p.gnn_data[9] != 0x02) {
  818. DEBUG2_3(printk("scsi(%ld): GNN_ID failed, rejected "
  819. "request, gnn_rsp:\n", ha->host_no));
  820. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gnn_data, 16));
  821. rval = QLA_FUNCTION_FAILED;
  822. } else {
  823. /* Save nodename */
  824. memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16],
  825. WWN_SIZE);
  826. DEBUG2_3(printk("scsi(%ld): GID_PT entry - "
  827. "nn %02x%02x%02x%02x%02x%02x%02x%02x "
  828. "pn %02x%02x%02x%02x%02x%02x%02x%02x "
  829. "portid=%02x%02x%02x.\n",
  830. ha->host_no,
  831. list[i].node_name[0], list[i].node_name[1],
  832. list[i].node_name[2], list[i].node_name[3],
  833. list[i].node_name[4], list[i].node_name[5],
  834. list[i].node_name[6], list[i].node_name[7],
  835. list[i].port_name[0], list[i].port_name[1],
  836. list[i].port_name[2], list[i].port_name[3],
  837. list[i].port_name[4], list[i].port_name[5],
  838. list[i].port_name[6], list[i].port_name[7],
  839. list[i].d_id.b.domain, list[i].d_id.b.area,
  840. list[i].d_id.b.al_pa));
  841. }
  842. /* Last device exit. */
  843. if (list[i].d_id.b.rsvd_1 != 0)
  844. break;
  845. }
  846. return (rval);
  847. }
  848. /**
  849. * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
  850. * @ha: HA context
  851. *
  852. * This command uses the old Exectute SNS Command mailbox routine.
  853. *
  854. * Returns 0 on success.
  855. */
  856. static int
  857. qla2x00_sns_rft_id(scsi_qla_host_t *ha)
  858. {
  859. int rval;
  860. struct sns_cmd_pkt *sns_cmd;
  861. /* Issue RFT_ID. */
  862. /* Prepare SNS command request. */
  863. sns_cmd = qla2x00_prep_sns_cmd(ha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
  864. RFT_ID_SNS_DATA_SIZE);
  865. /* Prepare SNS command arguments -- port_id, FC-4 types */
  866. sns_cmd->p.cmd.param[0] = ha->d_id.b.al_pa;
  867. sns_cmd->p.cmd.param[1] = ha->d_id.b.area;
  868. sns_cmd->p.cmd.param[2] = ha->d_id.b.domain;
  869. sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
  870. /* Execute SNS command. */
  871. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
  872. sizeof(struct sns_cmd_pkt));
  873. if (rval != QLA_SUCCESS) {
  874. /*EMPTY*/
  875. DEBUG2_3(printk("scsi(%ld): RFT_ID Send SNS failed (%d).\n",
  876. ha->host_no, rval));
  877. } else if (sns_cmd->p.rft_data[8] != 0x80 ||
  878. sns_cmd->p.rft_data[9] != 0x02) {
  879. DEBUG2_3(printk("scsi(%ld): RFT_ID failed, rejected request, "
  880. "rft_rsp:\n", ha->host_no));
  881. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.rft_data, 16));
  882. rval = QLA_FUNCTION_FAILED;
  883. } else {
  884. DEBUG2(printk("scsi(%ld): RFT_ID exiting normally.\n",
  885. ha->host_no));
  886. }
  887. return (rval);
  888. }
  889. /**
  890. * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
  891. * HBA.
  892. * @ha: HA context
  893. *
  894. * This command uses the old Exectute SNS Command mailbox routine.
  895. *
  896. * Returns 0 on success.
  897. */
  898. static int
  899. qla2x00_sns_rnn_id(scsi_qla_host_t *ha)
  900. {
  901. int rval;
  902. struct sns_cmd_pkt *sns_cmd;
  903. /* Issue RNN_ID. */
  904. /* Prepare SNS command request. */
  905. sns_cmd = qla2x00_prep_sns_cmd(ha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN,
  906. RNN_ID_SNS_DATA_SIZE);
  907. /* Prepare SNS command arguments -- port_id, nodename. */
  908. sns_cmd->p.cmd.param[0] = ha->d_id.b.al_pa;
  909. sns_cmd->p.cmd.param[1] = ha->d_id.b.area;
  910. sns_cmd->p.cmd.param[2] = ha->d_id.b.domain;
  911. sns_cmd->p.cmd.param[4] = ha->node_name[7];
  912. sns_cmd->p.cmd.param[5] = ha->node_name[6];
  913. sns_cmd->p.cmd.param[6] = ha->node_name[5];
  914. sns_cmd->p.cmd.param[7] = ha->node_name[4];
  915. sns_cmd->p.cmd.param[8] = ha->node_name[3];
  916. sns_cmd->p.cmd.param[9] = ha->node_name[2];
  917. sns_cmd->p.cmd.param[10] = ha->node_name[1];
  918. sns_cmd->p.cmd.param[11] = ha->node_name[0];
  919. /* Execute SNS command. */
  920. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
  921. sizeof(struct sns_cmd_pkt));
  922. if (rval != QLA_SUCCESS) {
  923. /*EMPTY*/
  924. DEBUG2_3(printk("scsi(%ld): RNN_ID Send SNS failed (%d).\n",
  925. ha->host_no, rval));
  926. } else if (sns_cmd->p.rnn_data[8] != 0x80 ||
  927. sns_cmd->p.rnn_data[9] != 0x02) {
  928. DEBUG2_3(printk("scsi(%ld): RNN_ID failed, rejected request, "
  929. "rnn_rsp:\n", ha->host_no));
  930. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.rnn_data, 16));
  931. rval = QLA_FUNCTION_FAILED;
  932. } else {
  933. DEBUG2(printk("scsi(%ld): RNN_ID exiting normally.\n",
  934. ha->host_no));
  935. }
  936. return (rval);
  937. }
  938. /**
  939. * qla2x00_mgmt_svr_login() - Login to fabric Managment Service.
  940. * @ha: HA context
  941. *
  942. * Returns 0 on success.
  943. */
  944. static int
  945. qla2x00_mgmt_svr_login(scsi_qla_host_t *ha)
  946. {
  947. int ret;
  948. uint16_t mb[MAILBOX_REGISTER_COUNT];
  949. ret = QLA_SUCCESS;
  950. if (ha->flags.management_server_logged_in)
  951. return ret;
  952. ha->isp_ops.fabric_login(ha, ha->mgmt_svr_loop_id, 0xff, 0xff, 0xfa,
  953. mb, BIT_1);
  954. if (mb[0] != MBS_COMMAND_COMPLETE) {
  955. DEBUG2_13(printk("%s(%ld): Failed MANAGEMENT_SERVER login: "
  956. "loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x\n",
  957. __func__, ha->host_no, ha->mgmt_svr_loop_id, mb[0], mb[1],
  958. mb[2], mb[6], mb[7]));
  959. ret = QLA_FUNCTION_FAILED;
  960. } else
  961. ha->flags.management_server_logged_in = 1;
  962. return ret;
  963. }
  964. /**
  965. * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
  966. * @ha: HA context
  967. * @req_size: request size in bytes
  968. * @rsp_size: response size in bytes
  969. *
  970. * Returns a pointer to the @ha's ms_iocb.
  971. */
  972. void *
  973. qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size,
  974. uint32_t rsp_size)
  975. {
  976. ms_iocb_entry_t *ms_pkt;
  977. ms_pkt = ha->ms_iocb;
  978. memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
  979. ms_pkt->entry_type = MS_IOCB_TYPE;
  980. ms_pkt->entry_count = 1;
  981. SET_TARGET_ID(ha, ms_pkt->loop_id, ha->mgmt_svr_loop_id);
  982. ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
  983. ms_pkt->timeout = __constant_cpu_to_le16(59);
  984. ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  985. ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
  986. ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
  987. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  988. ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  989. ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  990. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  991. ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  992. ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  993. ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
  994. return ms_pkt;
  995. }
  996. /**
  997. * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
  998. * @ha: HA context
  999. * @req_size: request size in bytes
  1000. * @rsp_size: response size in bytes
  1001. *
  1002. * Returns a pointer to the @ha's ms_iocb.
  1003. */
  1004. void *
  1005. qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size,
  1006. uint32_t rsp_size)
  1007. {
  1008. struct ct_entry_24xx *ct_pkt;
  1009. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1010. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  1011. ct_pkt->entry_type = CT_IOCB_TYPE;
  1012. ct_pkt->entry_count = 1;
  1013. ct_pkt->nport_handle = cpu_to_le16(ha->mgmt_svr_loop_id);
  1014. ct_pkt->timeout = __constant_cpu_to_le16(59);
  1015. ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  1016. ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
  1017. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  1018. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1019. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1020. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1021. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1022. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1023. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1024. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  1025. return ct_pkt;
  1026. }
  1027. static inline ms_iocb_entry_t *
  1028. qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size)
  1029. {
  1030. ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
  1031. struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1032. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  1033. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1034. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1035. } else {
  1036. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  1037. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  1038. }
  1039. return ms_pkt;
  1040. }
  1041. /**
  1042. * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
  1043. * @ct_req: CT request buffer
  1044. * @cmd: GS command
  1045. * @rsp_size: response size in bytes
  1046. *
  1047. * Returns a pointer to the intitialized @ct_req.
  1048. */
  1049. static inline struct ct_sns_req *
  1050. qla2x00_prep_ct_fdmi_req(struct ct_sns_req *ct_req, uint16_t cmd,
  1051. uint16_t rsp_size)
  1052. {
  1053. memset(ct_req, 0, sizeof(struct ct_sns_pkt));
  1054. ct_req->header.revision = 0x01;
  1055. ct_req->header.gs_type = 0xFA;
  1056. ct_req->header.gs_subtype = 0x10;
  1057. ct_req->command = cpu_to_be16(cmd);
  1058. ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  1059. return ct_req;
  1060. }
  1061. /**
  1062. * qla2x00_fdmi_rhba() -
  1063. * @ha: HA context
  1064. *
  1065. * Returns 0 on success.
  1066. */
  1067. static int
  1068. qla2x00_fdmi_rhba(scsi_qla_host_t *ha)
  1069. {
  1070. int rval, alen;
  1071. uint32_t size, sn;
  1072. ms_iocb_entry_t *ms_pkt;
  1073. struct ct_sns_req *ct_req;
  1074. struct ct_sns_rsp *ct_rsp;
  1075. uint8_t *entries;
  1076. struct ct_fdmi_hba_attr *eiter;
  1077. /* Issue RHBA */
  1078. /* Prepare common MS IOCB */
  1079. /* Request size adjusted after CT preparation */
  1080. ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RHBA_RSP_SIZE);
  1081. /* Prepare CT request */
  1082. ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RHBA_CMD,
  1083. RHBA_RSP_SIZE);
  1084. ct_rsp = &ha->ct_sns->p.rsp;
  1085. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1086. memcpy(ct_req->req.rhba.hba_identifier, ha->port_name, WWN_SIZE);
  1087. ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
  1088. memcpy(ct_req->req.rhba.port_name, ha->port_name, WWN_SIZE);
  1089. size = 2 * WWN_SIZE + 4 + 4;
  1090. /* Attributes */
  1091. ct_req->req.rhba.attrs.count =
  1092. __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
  1093. entries = ct_req->req.rhba.hba_identifier;
  1094. /* Nodename. */
  1095. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1096. eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
  1097. eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
  1098. memcpy(eiter->a.node_name, ha->node_name, WWN_SIZE);
  1099. size += 4 + WWN_SIZE;
  1100. DEBUG13(printk("%s(%ld): NODENAME=%02x%02x%02x%02x%02x%02x%02x%02x.\n",
  1101. __func__, ha->host_no,
  1102. eiter->a.node_name[0], eiter->a.node_name[1], eiter->a.node_name[2],
  1103. eiter->a.node_name[3], eiter->a.node_name[4], eiter->a.node_name[5],
  1104. eiter->a.node_name[6], eiter->a.node_name[7]));
  1105. /* Manufacturer. */
  1106. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1107. eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
  1108. strcpy(eiter->a.manufacturer, "QLogic Corporation");
  1109. alen = strlen(eiter->a.manufacturer);
  1110. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1111. eiter->len = cpu_to_be16(4 + alen);
  1112. size += 4 + alen;
  1113. DEBUG13(printk("%s(%ld): MANUFACTURER=%s.\n", __func__, ha->host_no,
  1114. eiter->a.manufacturer));
  1115. /* Serial number. */
  1116. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1117. eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
  1118. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  1119. sprintf(eiter->a.serial_num, "%c%05d", 'A' + sn / 100000, sn % 100000);
  1120. alen = strlen(eiter->a.serial_num);
  1121. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1122. eiter->len = cpu_to_be16(4 + alen);
  1123. size += 4 + alen;
  1124. DEBUG13(printk("%s(%ld): SERIALNO=%s.\n", __func__, ha->host_no,
  1125. eiter->a.serial_num));
  1126. /* Model name. */
  1127. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1128. eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
  1129. strcpy(eiter->a.model, ha->model_number);
  1130. alen = strlen(eiter->a.model);
  1131. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1132. eiter->len = cpu_to_be16(4 + alen);
  1133. size += 4 + alen;
  1134. DEBUG13(printk("%s(%ld): MODEL_NAME=%s.\n", __func__, ha->host_no,
  1135. eiter->a.model));
  1136. /* Model description. */
  1137. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1138. eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
  1139. if (ha->model_desc)
  1140. strncpy(eiter->a.model_desc, ha->model_desc, 80);
  1141. alen = strlen(eiter->a.model_desc);
  1142. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1143. eiter->len = cpu_to_be16(4 + alen);
  1144. size += 4 + alen;
  1145. DEBUG13(printk("%s(%ld): MODEL_DESC=%s.\n", __func__, ha->host_no,
  1146. eiter->a.model_desc));
  1147. /* Hardware version. */
  1148. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1149. eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
  1150. strcpy(eiter->a.hw_version, ha->adapter_id);
  1151. alen = strlen(eiter->a.hw_version);
  1152. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1153. eiter->len = cpu_to_be16(4 + alen);
  1154. size += 4 + alen;
  1155. DEBUG13(printk("%s(%ld): HARDWAREVER=%s.\n", __func__, ha->host_no,
  1156. eiter->a.hw_version));
  1157. /* Driver version. */
  1158. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1159. eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
  1160. strcpy(eiter->a.driver_version, qla2x00_version_str);
  1161. alen = strlen(eiter->a.driver_version);
  1162. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1163. eiter->len = cpu_to_be16(4 + alen);
  1164. size += 4 + alen;
  1165. DEBUG13(printk("%s(%ld): DRIVERVER=%s.\n", __func__, ha->host_no,
  1166. eiter->a.driver_version));
  1167. /* Option ROM version. */
  1168. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1169. eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
  1170. strcpy(eiter->a.orom_version, "0.00");
  1171. alen = strlen(eiter->a.orom_version);
  1172. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1173. eiter->len = cpu_to_be16(4 + alen);
  1174. size += 4 + alen;
  1175. DEBUG13(printk("%s(%ld): OPTROMVER=%s.\n", __func__, ha->host_no,
  1176. eiter->a.orom_version));
  1177. /* Firmware version */
  1178. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1179. eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
  1180. ha->isp_ops.fw_version_str(ha, eiter->a.fw_version);
  1181. alen = strlen(eiter->a.fw_version);
  1182. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1183. eiter->len = cpu_to_be16(4 + alen);
  1184. size += 4 + alen;
  1185. DEBUG13(printk("%s(%ld): FIRMWAREVER=%s.\n", __func__, ha->host_no,
  1186. eiter->a.fw_version));
  1187. /* Update MS request size. */
  1188. qla2x00_update_ms_fdmi_iocb(ha, size + 16);
  1189. DEBUG13(printk("%s(%ld): RHBA identifier="
  1190. "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
  1191. ha->host_no, ct_req->req.rhba.hba_identifier[0],
  1192. ct_req->req.rhba.hba_identifier[1],
  1193. ct_req->req.rhba.hba_identifier[2],
  1194. ct_req->req.rhba.hba_identifier[3],
  1195. ct_req->req.rhba.hba_identifier[4],
  1196. ct_req->req.rhba.hba_identifier[5],
  1197. ct_req->req.rhba.hba_identifier[6],
  1198. ct_req->req.rhba.hba_identifier[7], size));
  1199. DEBUG13(qla2x00_dump_buffer(entries, size));
  1200. /* Execute MS IOCB */
  1201. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1202. sizeof(ms_iocb_entry_t));
  1203. if (rval != QLA_SUCCESS) {
  1204. /*EMPTY*/
  1205. DEBUG2_3(printk("scsi(%ld): RHBA issue IOCB failed (%d).\n",
  1206. ha->host_no, rval));
  1207. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RHBA") !=
  1208. QLA_SUCCESS) {
  1209. rval = QLA_FUNCTION_FAILED;
  1210. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  1211. ct_rsp->header.explanation_code ==
  1212. CT_EXPL_ALREADY_REGISTERED) {
  1213. DEBUG2_13(printk("%s(%ld): HBA already registered.\n",
  1214. __func__, ha->host_no));
  1215. rval = QLA_ALREADY_REGISTERED;
  1216. }
  1217. } else {
  1218. DEBUG2(printk("scsi(%ld): RHBA exiting normally.\n",
  1219. ha->host_no));
  1220. }
  1221. return rval;
  1222. }
  1223. /**
  1224. * qla2x00_fdmi_dhba() -
  1225. * @ha: HA context
  1226. *
  1227. * Returns 0 on success.
  1228. */
  1229. static int
  1230. qla2x00_fdmi_dhba(scsi_qla_host_t *ha)
  1231. {
  1232. int rval;
  1233. ms_iocb_entry_t *ms_pkt;
  1234. struct ct_sns_req *ct_req;
  1235. struct ct_sns_rsp *ct_rsp;
  1236. /* Issue RPA */
  1237. /* Prepare common MS IOCB */
  1238. ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, DHBA_REQ_SIZE,
  1239. DHBA_RSP_SIZE);
  1240. /* Prepare CT request */
  1241. ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, DHBA_CMD,
  1242. DHBA_RSP_SIZE);
  1243. ct_rsp = &ha->ct_sns->p.rsp;
  1244. /* Prepare FDMI command arguments -- portname. */
  1245. memcpy(ct_req->req.dhba.port_name, ha->port_name, WWN_SIZE);
  1246. DEBUG13(printk("%s(%ld): DHBA portname="
  1247. "%02x%02x%02x%02x%02x%02x%02x%02x.\n", __func__, ha->host_no,
  1248. ct_req->req.dhba.port_name[0], ct_req->req.dhba.port_name[1],
  1249. ct_req->req.dhba.port_name[2], ct_req->req.dhba.port_name[3],
  1250. ct_req->req.dhba.port_name[4], ct_req->req.dhba.port_name[5],
  1251. ct_req->req.dhba.port_name[6], ct_req->req.dhba.port_name[7]));
  1252. /* Execute MS IOCB */
  1253. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1254. sizeof(ms_iocb_entry_t));
  1255. if (rval != QLA_SUCCESS) {
  1256. /*EMPTY*/
  1257. DEBUG2_3(printk("scsi(%ld): DHBA issue IOCB failed (%d).\n",
  1258. ha->host_no, rval));
  1259. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "DHBA") !=
  1260. QLA_SUCCESS) {
  1261. rval = QLA_FUNCTION_FAILED;
  1262. } else {
  1263. DEBUG2(printk("scsi(%ld): DHBA exiting normally.\n",
  1264. ha->host_no));
  1265. }
  1266. return rval;
  1267. }
  1268. /**
  1269. * qla2x00_fdmi_rpa() -
  1270. * @ha: HA context
  1271. *
  1272. * Returns 0 on success.
  1273. */
  1274. static int
  1275. qla2x00_fdmi_rpa(scsi_qla_host_t *ha)
  1276. {
  1277. int rval, alen;
  1278. uint32_t size, max_frame_size;
  1279. ms_iocb_entry_t *ms_pkt;
  1280. struct ct_sns_req *ct_req;
  1281. struct ct_sns_rsp *ct_rsp;
  1282. uint8_t *entries;
  1283. struct ct_fdmi_port_attr *eiter;
  1284. struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
  1285. /* Issue RPA */
  1286. /* Prepare common MS IOCB */
  1287. /* Request size adjusted after CT preparation */
  1288. ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RPA_RSP_SIZE);
  1289. /* Prepare CT request */
  1290. ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RPA_CMD,
  1291. RPA_RSP_SIZE);
  1292. ct_rsp = &ha->ct_sns->p.rsp;
  1293. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1294. memcpy(ct_req->req.rpa.port_name, ha->port_name, WWN_SIZE);
  1295. size = WWN_SIZE + 4;
  1296. /* Attributes */
  1297. ct_req->req.rpa.attrs.count =
  1298. __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
  1299. entries = ct_req->req.rpa.port_name;
  1300. /* FC4 types. */
  1301. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1302. eiter->type = __constant_cpu_to_be16(FDMI_PORT_FC4_TYPES);
  1303. eiter->len = __constant_cpu_to_be16(4 + 32);
  1304. eiter->a.fc4_types[2] = 0x01;
  1305. size += 4 + 32;
  1306. DEBUG13(printk("%s(%ld): FC4_TYPES=%02x %02x.\n", __func__, ha->host_no,
  1307. eiter->a.fc4_types[2], eiter->a.fc4_types[1]));
  1308. /* Supported speed. */
  1309. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1310. eiter->type = __constant_cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
  1311. eiter->len = __constant_cpu_to_be16(4 + 4);
  1312. if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
  1313. eiter->a.sup_speed = __constant_cpu_to_be32(4);
  1314. else if (IS_QLA23XX(ha))
  1315. eiter->a.sup_speed = __constant_cpu_to_be32(2);
  1316. else
  1317. eiter->a.sup_speed = __constant_cpu_to_be32(1);
  1318. size += 4 + 4;
  1319. DEBUG13(printk("%s(%ld): SUPPORTED_SPEED=%x.\n", __func__, ha->host_no,
  1320. eiter->a.sup_speed));
  1321. /* Current speed. */
  1322. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1323. eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
  1324. eiter->len = __constant_cpu_to_be16(4 + 4);
  1325. switch (ha->link_data_rate) {
  1326. case 0:
  1327. eiter->a.cur_speed = __constant_cpu_to_be32(1);
  1328. break;
  1329. case 1:
  1330. eiter->a.cur_speed = __constant_cpu_to_be32(2);
  1331. break;
  1332. case 3:
  1333. eiter->a.cur_speed = __constant_cpu_to_be32(4);
  1334. break;
  1335. }
  1336. size += 4 + 4;
  1337. DEBUG13(printk("%s(%ld): CURRENT_SPEED=%x.\n", __func__, ha->host_no,
  1338. eiter->a.cur_speed));
  1339. /* Max frame size. */
  1340. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1341. eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
  1342. eiter->len = __constant_cpu_to_be16(4 + 4);
  1343. max_frame_size = IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
  1344. (uint32_t) icb24->frame_payload_size:
  1345. (uint32_t) ha->init_cb->frame_payload_size;
  1346. eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
  1347. size += 4 + 4;
  1348. DEBUG13(printk("%s(%ld): MAX_FRAME_SIZE=%x.\n", __func__, ha->host_no,
  1349. eiter->a.max_frame_size));
  1350. /* OS device name. */
  1351. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1352. eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
  1353. sprintf(eiter->a.os_dev_name, "/proc/scsi/qla2xxx/%ld", ha->host_no);
  1354. alen = strlen(eiter->a.os_dev_name);
  1355. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1356. eiter->len = cpu_to_be16(4 + alen);
  1357. size += 4 + alen;
  1358. DEBUG13(printk("%s(%ld): OS_DEVICE_NAME=%s.\n", __func__, ha->host_no,
  1359. eiter->a.os_dev_name));
  1360. /* Hostname. */
  1361. if (strlen(fc_host_system_hostname(ha->host))) {
  1362. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1363. eiter->type = __constant_cpu_to_be16(FDMI_PORT_HOST_NAME);
  1364. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  1365. "%s", fc_host_system_hostname(ha->host));
  1366. alen = strlen(eiter->a.host_name);
  1367. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1368. eiter->len = cpu_to_be16(4 + alen);
  1369. size += 4 + alen;
  1370. DEBUG13(printk("%s(%ld): HOSTNAME=%s.\n", __func__,
  1371. ha->host_no, eiter->a.host_name));
  1372. }
  1373. /* Update MS request size. */
  1374. qla2x00_update_ms_fdmi_iocb(ha, size + 16);
  1375. DEBUG13(printk("%s(%ld): RPA portname="
  1376. "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
  1377. ha->host_no, ct_req->req.rpa.port_name[0],
  1378. ct_req->req.rpa.port_name[1], ct_req->req.rpa.port_name[2],
  1379. ct_req->req.rpa.port_name[3], ct_req->req.rpa.port_name[4],
  1380. ct_req->req.rpa.port_name[5], ct_req->req.rpa.port_name[6],
  1381. ct_req->req.rpa.port_name[7], size));
  1382. DEBUG13(qla2x00_dump_buffer(entries, size));
  1383. /* Execute MS IOCB */
  1384. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1385. sizeof(ms_iocb_entry_t));
  1386. if (rval != QLA_SUCCESS) {
  1387. /*EMPTY*/
  1388. DEBUG2_3(printk("scsi(%ld): RPA issue IOCB failed (%d).\n",
  1389. ha->host_no, rval));
  1390. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RPA") !=
  1391. QLA_SUCCESS) {
  1392. rval = QLA_FUNCTION_FAILED;
  1393. } else {
  1394. DEBUG2(printk("scsi(%ld): RPA exiting normally.\n",
  1395. ha->host_no));
  1396. }
  1397. return rval;
  1398. }
  1399. /**
  1400. * qla2x00_fdmi_register() -
  1401. * @ha: HA context
  1402. *
  1403. * Returns 0 on success.
  1404. */
  1405. int
  1406. qla2x00_fdmi_register(scsi_qla_host_t *ha)
  1407. {
  1408. int rval;
  1409. rval = qla2x00_mgmt_svr_login(ha);
  1410. if (rval)
  1411. return rval;
  1412. rval = qla2x00_fdmi_rhba(ha);
  1413. if (rval) {
  1414. if (rval != QLA_ALREADY_REGISTERED)
  1415. return rval;
  1416. rval = qla2x00_fdmi_dhba(ha);
  1417. if (rval)
  1418. return rval;
  1419. rval = qla2x00_fdmi_rhba(ha);
  1420. if (rval)
  1421. return rval;
  1422. }
  1423. rval = qla2x00_fdmi_rpa(ha);
  1424. return rval;
  1425. }
  1426. /**
  1427. * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
  1428. * @ha: HA context
  1429. * @list: switch info entries to populate
  1430. *
  1431. * Returns 0 on success.
  1432. */
  1433. int
  1434. qla2x00_gfpn_id(scsi_qla_host_t *ha, sw_info_t *list)
  1435. {
  1436. int rval;
  1437. uint16_t i;
  1438. ms_iocb_entry_t *ms_pkt;
  1439. struct ct_sns_req *ct_req;
  1440. struct ct_sns_rsp *ct_rsp;
  1441. if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
  1442. return QLA_FUNCTION_FAILED;
  1443. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  1444. /* Issue GFPN_ID */
  1445. memset(list[i].fabric_port_name, 0, WWN_SIZE);
  1446. /* Prepare common MS IOCB */
  1447. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GFPN_ID_REQ_SIZE,
  1448. GFPN_ID_RSP_SIZE);
  1449. /* Prepare CT request */
  1450. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GFPN_ID_CMD,
  1451. GFPN_ID_RSP_SIZE);
  1452. ct_rsp = &ha->ct_sns->p.rsp;
  1453. /* Prepare CT arguments -- port_id */
  1454. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  1455. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  1456. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  1457. /* Execute MS IOCB */
  1458. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1459. sizeof(ms_iocb_entry_t));
  1460. if (rval != QLA_SUCCESS) {
  1461. /*EMPTY*/
  1462. DEBUG2_3(printk("scsi(%ld): GFPN_ID issue IOCB "
  1463. "failed (%d).\n", ha->host_no, rval));
  1464. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
  1465. "GFPN_ID") != QLA_SUCCESS) {
  1466. rval = QLA_FUNCTION_FAILED;
  1467. } else {
  1468. /* Save fabric portname */
  1469. memcpy(list[i].fabric_port_name,
  1470. ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
  1471. }
  1472. /* Last device exit. */
  1473. if (list[i].d_id.b.rsvd_1 != 0)
  1474. break;
  1475. }
  1476. return (rval);
  1477. }
  1478. static inline void *
  1479. qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *ha, uint32_t req_size,
  1480. uint32_t rsp_size)
  1481. {
  1482. struct ct_entry_24xx *ct_pkt;
  1483. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1484. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  1485. ct_pkt->entry_type = CT_IOCB_TYPE;
  1486. ct_pkt->entry_count = 1;
  1487. ct_pkt->nport_handle = cpu_to_le16(ha->mgmt_svr_loop_id);
  1488. ct_pkt->timeout = __constant_cpu_to_le16(59);
  1489. ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  1490. ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
  1491. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  1492. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1493. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1494. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1495. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1496. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1497. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1498. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  1499. return ct_pkt;
  1500. }
  1501. static inline struct ct_sns_req *
  1502. qla24xx_prep_ct_fm_req(struct ct_sns_req *ct_req, uint16_t cmd,
  1503. uint16_t rsp_size)
  1504. {
  1505. memset(ct_req, 0, sizeof(struct ct_sns_pkt));
  1506. ct_req->header.revision = 0x01;
  1507. ct_req->header.gs_type = 0xFA;
  1508. ct_req->header.gs_subtype = 0x01;
  1509. ct_req->command = cpu_to_be16(cmd);
  1510. ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  1511. return ct_req;
  1512. }
  1513. /**
  1514. * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
  1515. * @ha: HA context
  1516. * @list: switch info entries to populate
  1517. *
  1518. * Returns 0 on success.
  1519. */
  1520. int
  1521. qla2x00_gpsc(scsi_qla_host_t *ha, sw_info_t *list)
  1522. {
  1523. int rval;
  1524. uint16_t i;
  1525. ms_iocb_entry_t *ms_pkt;
  1526. struct ct_sns_req *ct_req;
  1527. struct ct_sns_rsp *ct_rsp;
  1528. if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
  1529. return QLA_FUNCTION_FAILED;
  1530. if (!ha->flags.gpsc_supported)
  1531. return QLA_FUNCTION_FAILED;
  1532. rval = qla2x00_mgmt_svr_login(ha);
  1533. if (rval)
  1534. return rval;
  1535. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  1536. /* Issue GFPN_ID */
  1537. list[i].fp_speeds = list[i].fp_speed = 0;
  1538. /* Prepare common MS IOCB */
  1539. ms_pkt = qla24xx_prep_ms_fm_iocb(ha, GPSC_REQ_SIZE,
  1540. GPSC_RSP_SIZE);
  1541. /* Prepare CT request */
  1542. ct_req = qla24xx_prep_ct_fm_req(&ha->ct_sns->p.req,
  1543. GPSC_CMD, GPSC_RSP_SIZE);
  1544. ct_rsp = &ha->ct_sns->p.rsp;
  1545. /* Prepare CT arguments -- port_name */
  1546. memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
  1547. WWN_SIZE);
  1548. /* Execute MS IOCB */
  1549. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1550. sizeof(ms_iocb_entry_t));
  1551. if (rval != QLA_SUCCESS) {
  1552. /*EMPTY*/
  1553. DEBUG2_3(printk("scsi(%ld): GPSC issue IOCB "
  1554. "failed (%d).\n", ha->host_no, rval));
  1555. } else if ((rval = qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
  1556. "GPSC")) != QLA_SUCCESS) {
  1557. /* FM command unsupported? */
  1558. if (rval == QLA_INVALID_COMMAND &&
  1559. ct_rsp->header.reason_code ==
  1560. CT_REASON_INVALID_COMMAND_CODE) {
  1561. DEBUG2(printk("scsi(%ld): GPSC command "
  1562. "unsupported, disabling query...\n",
  1563. ha->host_no));
  1564. ha->flags.gpsc_supported = 0;
  1565. rval = QLA_FUNCTION_FAILED;
  1566. break;
  1567. }
  1568. rval = QLA_FUNCTION_FAILED;
  1569. } else {
  1570. /* Save portname */
  1571. list[i].fp_speeds = ct_rsp->rsp.gpsc.speeds;
  1572. list[i].fp_speed = ct_rsp->rsp.gpsc.speed;
  1573. DEBUG2_3(printk("scsi(%ld): GPSC ext entry - "
  1574. "fpn %02x%02x%02x%02x%02x%02x%02x%02x speeds=%04x "
  1575. "speed=%04x.\n", ha->host_no,
  1576. list[i].fabric_port_name[0],
  1577. list[i].fabric_port_name[1],
  1578. list[i].fabric_port_name[2],
  1579. list[i].fabric_port_name[3],
  1580. list[i].fabric_port_name[4],
  1581. list[i].fabric_port_name[5],
  1582. list[i].fabric_port_name[6],
  1583. list[i].fabric_port_name[7],
  1584. be16_to_cpu(list[i].fp_speeds),
  1585. be16_to_cpu(list[i].fp_speed)));
  1586. }
  1587. /* Last device exit. */
  1588. if (list[i].d_id.b.rsvd_1 != 0)
  1589. break;
  1590. }
  1591. return (rval);
  1592. }