qla_gs.c 53 KB

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