qla_gs.c 55 KB

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