qla_gs.c 47 KB

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