qla_gs.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
  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|BIT_0);
  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_QLA81XX(ha))
  1339. eiter->a.sup_speed = __constant_cpu_to_be32(
  1340. FDMI_PORT_SPEED_10GB);
  1341. else if (IS_QLA25XX(ha))
  1342. eiter->a.sup_speed = __constant_cpu_to_be32(
  1343. FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
  1344. FDMI_PORT_SPEED_4GB|FDMI_PORT_SPEED_8GB);
  1345. else if (IS_QLA24XX_TYPE(ha))
  1346. eiter->a.sup_speed = __constant_cpu_to_be32(
  1347. FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB|
  1348. FDMI_PORT_SPEED_4GB);
  1349. else if (IS_QLA23XX(ha))
  1350. eiter->a.sup_speed =__constant_cpu_to_be32(
  1351. FDMI_PORT_SPEED_1GB|FDMI_PORT_SPEED_2GB);
  1352. else
  1353. eiter->a.sup_speed = __constant_cpu_to_be32(
  1354. FDMI_PORT_SPEED_1GB);
  1355. size += 4 + 4;
  1356. DEBUG13(printk("%s(%ld): SUPPORTED_SPEED=%x.\n", __func__, vha->host_no,
  1357. eiter->a.sup_speed));
  1358. /* Current speed. */
  1359. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1360. eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
  1361. eiter->len = __constant_cpu_to_be16(4 + 4);
  1362. switch (ha->link_data_rate) {
  1363. case PORT_SPEED_1GB:
  1364. eiter->a.cur_speed =
  1365. __constant_cpu_to_be32(FDMI_PORT_SPEED_1GB);
  1366. break;
  1367. case PORT_SPEED_2GB:
  1368. eiter->a.cur_speed =
  1369. __constant_cpu_to_be32(FDMI_PORT_SPEED_2GB);
  1370. break;
  1371. case PORT_SPEED_4GB:
  1372. eiter->a.cur_speed =
  1373. __constant_cpu_to_be32(FDMI_PORT_SPEED_4GB);
  1374. break;
  1375. case PORT_SPEED_8GB:
  1376. eiter->a.cur_speed =
  1377. __constant_cpu_to_be32(FDMI_PORT_SPEED_8GB);
  1378. break;
  1379. case PORT_SPEED_10GB:
  1380. eiter->a.cur_speed =
  1381. __constant_cpu_to_be32(FDMI_PORT_SPEED_10GB);
  1382. break;
  1383. default:
  1384. eiter->a.cur_speed =
  1385. __constant_cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
  1386. break;
  1387. }
  1388. size += 4 + 4;
  1389. DEBUG13(printk("%s(%ld): CURRENT_SPEED=%x.\n", __func__, vha->host_no,
  1390. eiter->a.cur_speed));
  1391. /* Max frame size. */
  1392. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1393. eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
  1394. eiter->len = __constant_cpu_to_be16(4 + 4);
  1395. max_frame_size = IS_FWI2_CAPABLE(ha) ?
  1396. le16_to_cpu(icb24->frame_payload_size):
  1397. le16_to_cpu(ha->init_cb->frame_payload_size);
  1398. eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
  1399. size += 4 + 4;
  1400. DEBUG13(printk("%s(%ld): MAX_FRAME_SIZE=%x.\n", __func__, vha->host_no,
  1401. eiter->a.max_frame_size));
  1402. /* OS device name. */
  1403. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1404. eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
  1405. strcpy(eiter->a.os_dev_name, QLA2XXX_DRIVER_NAME);
  1406. alen = strlen(eiter->a.os_dev_name);
  1407. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1408. eiter->len = cpu_to_be16(4 + alen);
  1409. size += 4 + alen;
  1410. DEBUG13(printk("%s(%ld): OS_DEVICE_NAME=%s.\n", __func__, vha->host_no,
  1411. eiter->a.os_dev_name));
  1412. /* Hostname. */
  1413. if (strlen(fc_host_system_hostname(vha->host))) {
  1414. ct_req->req.rpa.attrs.count =
  1415. __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
  1416. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1417. eiter->type = __constant_cpu_to_be16(FDMI_PORT_HOST_NAME);
  1418. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  1419. "%s", fc_host_system_hostname(vha->host));
  1420. alen = strlen(eiter->a.host_name);
  1421. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1422. eiter->len = cpu_to_be16(4 + alen);
  1423. size += 4 + alen;
  1424. DEBUG13(printk("%s(%ld): HOSTNAME=%s.\n", __func__,
  1425. vha->host_no, eiter->a.host_name));
  1426. }
  1427. /* Update MS request size. */
  1428. qla2x00_update_ms_fdmi_iocb(vha, size + 16);
  1429. DEBUG13(printk("%s(%ld): RPA portname="
  1430. "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
  1431. vha->host_no, ct_req->req.rpa.port_name[0],
  1432. ct_req->req.rpa.port_name[1], ct_req->req.rpa.port_name[2],
  1433. ct_req->req.rpa.port_name[3], ct_req->req.rpa.port_name[4],
  1434. ct_req->req.rpa.port_name[5], ct_req->req.rpa.port_name[6],
  1435. ct_req->req.rpa.port_name[7], size));
  1436. DEBUG13(qla2x00_dump_buffer(entries, size));
  1437. /* Execute MS IOCB */
  1438. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1439. sizeof(ms_iocb_entry_t));
  1440. if (rval != QLA_SUCCESS) {
  1441. /*EMPTY*/
  1442. DEBUG2_3(printk("scsi(%ld): RPA issue IOCB failed (%d).\n",
  1443. vha->host_no, rval));
  1444. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
  1445. QLA_SUCCESS) {
  1446. rval = QLA_FUNCTION_FAILED;
  1447. } else {
  1448. DEBUG2(printk("scsi(%ld): RPA exiting normally.\n",
  1449. vha->host_no));
  1450. }
  1451. return rval;
  1452. }
  1453. /**
  1454. * qla2x00_fdmi_register() -
  1455. * @ha: HA context
  1456. *
  1457. * Returns 0 on success.
  1458. */
  1459. int
  1460. qla2x00_fdmi_register(scsi_qla_host_t *vha)
  1461. {
  1462. int rval;
  1463. struct qla_hw_data *ha = vha->hw;
  1464. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1465. return QLA_FUNCTION_FAILED;
  1466. rval = qla2x00_mgmt_svr_login(vha);
  1467. if (rval)
  1468. return rval;
  1469. rval = qla2x00_fdmi_rhba(vha);
  1470. if (rval) {
  1471. if (rval != QLA_ALREADY_REGISTERED)
  1472. return rval;
  1473. rval = qla2x00_fdmi_dhba(vha);
  1474. if (rval)
  1475. return rval;
  1476. rval = qla2x00_fdmi_rhba(vha);
  1477. if (rval)
  1478. return rval;
  1479. }
  1480. rval = qla2x00_fdmi_rpa(vha);
  1481. return rval;
  1482. }
  1483. /**
  1484. * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
  1485. * @ha: HA context
  1486. * @list: switch info entries to populate
  1487. *
  1488. * Returns 0 on success.
  1489. */
  1490. int
  1491. qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
  1492. {
  1493. int rval;
  1494. uint16_t i;
  1495. struct qla_hw_data *ha = vha->hw;
  1496. ms_iocb_entry_t *ms_pkt;
  1497. struct ct_sns_req *ct_req;
  1498. struct ct_sns_rsp *ct_rsp;
  1499. if (!IS_IIDMA_CAPABLE(ha))
  1500. return QLA_FUNCTION_FAILED;
  1501. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  1502. /* Issue GFPN_ID */
  1503. /* Prepare common MS IOCB */
  1504. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, GFPN_ID_REQ_SIZE,
  1505. GFPN_ID_RSP_SIZE);
  1506. /* Prepare CT request */
  1507. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GFPN_ID_CMD,
  1508. GFPN_ID_RSP_SIZE);
  1509. ct_rsp = &ha->ct_sns->p.rsp;
  1510. /* Prepare CT arguments -- port_id */
  1511. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  1512. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  1513. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  1514. /* Execute MS IOCB */
  1515. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1516. sizeof(ms_iocb_entry_t));
  1517. if (rval != QLA_SUCCESS) {
  1518. /*EMPTY*/
  1519. DEBUG2_3(printk("scsi(%ld): GFPN_ID issue IOCB "
  1520. "failed (%d).\n", vha->host_no, rval));
  1521. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  1522. "GFPN_ID") != QLA_SUCCESS) {
  1523. rval = QLA_FUNCTION_FAILED;
  1524. } else {
  1525. /* Save fabric portname */
  1526. memcpy(list[i].fabric_port_name,
  1527. ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
  1528. }
  1529. /* Last device exit. */
  1530. if (list[i].d_id.b.rsvd_1 != 0)
  1531. break;
  1532. }
  1533. return (rval);
  1534. }
  1535. static inline void *
  1536. qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *vha, uint32_t req_size,
  1537. uint32_t rsp_size)
  1538. {
  1539. struct ct_entry_24xx *ct_pkt;
  1540. struct qla_hw_data *ha = vha->hw;
  1541. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1542. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  1543. ct_pkt->entry_type = CT_IOCB_TYPE;
  1544. ct_pkt->entry_count = 1;
  1545. ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
  1546. ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  1547. ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  1548. ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
  1549. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  1550. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1551. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1552. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1553. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1554. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1555. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1556. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  1557. ct_pkt->vp_index = vha->vp_idx;
  1558. return ct_pkt;
  1559. }
  1560. static inline struct ct_sns_req *
  1561. qla24xx_prep_ct_fm_req(struct ct_sns_req *ct_req, uint16_t cmd,
  1562. uint16_t rsp_size)
  1563. {
  1564. memset(ct_req, 0, sizeof(struct ct_sns_pkt));
  1565. ct_req->header.revision = 0x01;
  1566. ct_req->header.gs_type = 0xFA;
  1567. ct_req->header.gs_subtype = 0x01;
  1568. ct_req->command = cpu_to_be16(cmd);
  1569. ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  1570. return ct_req;
  1571. }
  1572. /**
  1573. * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
  1574. * @ha: HA context
  1575. * @list: switch info entries to populate
  1576. *
  1577. * Returns 0 on success.
  1578. */
  1579. int
  1580. qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list)
  1581. {
  1582. int rval;
  1583. uint16_t i;
  1584. struct qla_hw_data *ha = vha->hw;
  1585. ms_iocb_entry_t *ms_pkt;
  1586. struct ct_sns_req *ct_req;
  1587. struct ct_sns_rsp *ct_rsp;
  1588. if (!IS_IIDMA_CAPABLE(ha))
  1589. return QLA_FUNCTION_FAILED;
  1590. if (!ha->flags.gpsc_supported)
  1591. return QLA_FUNCTION_FAILED;
  1592. rval = qla2x00_mgmt_svr_login(vha);
  1593. if (rval)
  1594. return rval;
  1595. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  1596. /* Issue GFPN_ID */
  1597. /* Prepare common MS IOCB */
  1598. ms_pkt = qla24xx_prep_ms_fm_iocb(vha, GPSC_REQ_SIZE,
  1599. GPSC_RSP_SIZE);
  1600. /* Prepare CT request */
  1601. ct_req = qla24xx_prep_ct_fm_req(&ha->ct_sns->p.req,
  1602. GPSC_CMD, GPSC_RSP_SIZE);
  1603. ct_rsp = &ha->ct_sns->p.rsp;
  1604. /* Prepare CT arguments -- port_name */
  1605. memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
  1606. WWN_SIZE);
  1607. /* Execute MS IOCB */
  1608. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1609. sizeof(ms_iocb_entry_t));
  1610. if (rval != QLA_SUCCESS) {
  1611. /*EMPTY*/
  1612. DEBUG2_3(printk("scsi(%ld): GPSC issue IOCB "
  1613. "failed (%d).\n", vha->host_no, rval));
  1614. } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  1615. "GPSC")) != QLA_SUCCESS) {
  1616. /* FM command unsupported? */
  1617. if (rval == QLA_INVALID_COMMAND &&
  1618. (ct_rsp->header.reason_code ==
  1619. CT_REASON_INVALID_COMMAND_CODE ||
  1620. ct_rsp->header.reason_code ==
  1621. CT_REASON_COMMAND_UNSUPPORTED)) {
  1622. DEBUG2(printk("scsi(%ld): GPSC command "
  1623. "unsupported, disabling query...\n",
  1624. vha->host_no));
  1625. ha->flags.gpsc_supported = 0;
  1626. rval = QLA_FUNCTION_FAILED;
  1627. break;
  1628. }
  1629. rval = QLA_FUNCTION_FAILED;
  1630. } else {
  1631. /* Save port-speed */
  1632. switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
  1633. case BIT_15:
  1634. list[i].fp_speed = PORT_SPEED_1GB;
  1635. break;
  1636. case BIT_14:
  1637. list[i].fp_speed = PORT_SPEED_2GB;
  1638. break;
  1639. case BIT_13:
  1640. list[i].fp_speed = PORT_SPEED_4GB;
  1641. break;
  1642. case BIT_12:
  1643. list[i].fp_speed = PORT_SPEED_10GB;
  1644. break;
  1645. case BIT_11:
  1646. list[i].fp_speed = PORT_SPEED_8GB;
  1647. break;
  1648. }
  1649. DEBUG2_3(printk("scsi(%ld): GPSC ext entry - "
  1650. "fpn %02x%02x%02x%02x%02x%02x%02x%02x speeds=%04x "
  1651. "speed=%04x.\n", vha->host_no,
  1652. list[i].fabric_port_name[0],
  1653. list[i].fabric_port_name[1],
  1654. list[i].fabric_port_name[2],
  1655. list[i].fabric_port_name[3],
  1656. list[i].fabric_port_name[4],
  1657. list[i].fabric_port_name[5],
  1658. list[i].fabric_port_name[6],
  1659. list[i].fabric_port_name[7],
  1660. be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
  1661. be16_to_cpu(ct_rsp->rsp.gpsc.speed)));
  1662. }
  1663. /* Last device exit. */
  1664. if (list[i].d_id.b.rsvd_1 != 0)
  1665. break;
  1666. }
  1667. return (rval);
  1668. }