qla_gs.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845
  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. void
  526. qla2x00_get_sym_node_name(scsi_qla_host_t *ha, uint8_t *snn)
  527. {
  528. sprintf(snn, "%s FW:v%d.%02d.%02d DVR:v%s",ha->model_number,
  529. ha->fw_major_version, ha->fw_minor_version,
  530. ha->fw_subminor_version, qla2x00_version_str);
  531. }
  532. /**
  533. * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
  534. * @ha: HA context
  535. *
  536. * Returns 0 on success.
  537. */
  538. int
  539. qla2x00_rsnn_nn(scsi_qla_host_t *ha)
  540. {
  541. int rval;
  542. ms_iocb_entry_t *ms_pkt;
  543. struct ct_sns_req *ct_req;
  544. struct ct_sns_rsp *ct_rsp;
  545. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  546. DEBUG2(printk("scsi(%ld): RSNN_ID call unsupported on "
  547. "ISP2100/ISP2200.\n", ha->host_no));
  548. return (QLA_SUCCESS);
  549. }
  550. /* Issue RSNN_NN */
  551. /* Prepare common MS IOCB */
  552. /* Request size adjusted after CT preparation */
  553. ms_pkt = ha->isp_ops.prep_ms_iocb(ha, 0, RSNN_NN_RSP_SIZE);
  554. /* Prepare CT request */
  555. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RSNN_NN_CMD,
  556. RSNN_NN_RSP_SIZE);
  557. ct_rsp = &ha->ct_sns->p.rsp;
  558. /* Prepare CT arguments -- node_name, symbolic node_name, size */
  559. memcpy(ct_req->req.rsnn_nn.node_name, ha->node_name, WWN_SIZE);
  560. /* Prepare the Symbolic Node Name */
  561. qla2x00_get_sym_node_name(ha, ct_req->req.rsnn_nn.sym_node_name);
  562. /* Calculate SNN length */
  563. ct_req->req.rsnn_nn.name_len =
  564. (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name);
  565. /* Update MS IOCB request */
  566. ms_pkt->req_bytecount =
  567. cpu_to_le32(24 + 1 + ct_req->req.rsnn_nn.name_len);
  568. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  569. /* Execute MS IOCB */
  570. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  571. sizeof(ms_iocb_entry_t));
  572. if (rval != QLA_SUCCESS) {
  573. /*EMPTY*/
  574. DEBUG2_3(printk("scsi(%ld): RSNN_NN issue IOCB failed (%d).\n",
  575. ha->host_no, rval));
  576. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RSNN_NN") !=
  577. QLA_SUCCESS) {
  578. rval = QLA_FUNCTION_FAILED;
  579. } else {
  580. DEBUG2(printk("scsi(%ld): RSNN_NN exiting normally.\n",
  581. ha->host_no));
  582. }
  583. return (rval);
  584. }
  585. /**
  586. * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query.
  587. * @ha: HA context
  588. * @cmd: GS command
  589. * @scmd_len: Subcommand length
  590. * @data_size: response size in bytes
  591. *
  592. * Returns a pointer to the @ha's sns_cmd.
  593. */
  594. static inline struct sns_cmd_pkt *
  595. qla2x00_prep_sns_cmd(scsi_qla_host_t *ha, uint16_t cmd, uint16_t scmd_len,
  596. uint16_t data_size)
  597. {
  598. uint16_t wc;
  599. struct sns_cmd_pkt *sns_cmd;
  600. sns_cmd = ha->sns_cmd;
  601. memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt));
  602. wc = data_size / 2; /* Size in 16bit words. */
  603. sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc);
  604. sns_cmd->p.cmd.buffer_address[0] = cpu_to_le32(LSD(ha->sns_cmd_dma));
  605. sns_cmd->p.cmd.buffer_address[1] = cpu_to_le32(MSD(ha->sns_cmd_dma));
  606. sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len);
  607. sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd);
  608. wc = (data_size - 16) / 4; /* Size in 32bit words. */
  609. sns_cmd->p.cmd.size = cpu_to_le16(wc);
  610. return (sns_cmd);
  611. }
  612. /**
  613. * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
  614. * @ha: HA context
  615. * @fcport: fcport entry to updated
  616. *
  617. * This command uses the old Exectute SNS Command mailbox routine.
  618. *
  619. * Returns 0 on success.
  620. */
  621. static int
  622. qla2x00_sns_ga_nxt(scsi_qla_host_t *ha, fc_port_t *fcport)
  623. {
  624. int rval;
  625. struct sns_cmd_pkt *sns_cmd;
  626. /* Issue GA_NXT. */
  627. /* Prepare SNS command request. */
  628. sns_cmd = qla2x00_prep_sns_cmd(ha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN,
  629. GA_NXT_SNS_DATA_SIZE);
  630. /* Prepare SNS command arguments -- port_id. */
  631. sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa;
  632. sns_cmd->p.cmd.param[1] = fcport->d_id.b.area;
  633. sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain;
  634. /* Execute SNS command. */
  635. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2,
  636. sizeof(struct sns_cmd_pkt));
  637. if (rval != QLA_SUCCESS) {
  638. /*EMPTY*/
  639. DEBUG2_3(printk("scsi(%ld): GA_NXT Send SNS failed (%d).\n",
  640. ha->host_no, rval));
  641. } else if (sns_cmd->p.gan_data[8] != 0x80 ||
  642. sns_cmd->p.gan_data[9] != 0x02) {
  643. DEBUG2_3(printk("scsi(%ld): GA_NXT failed, rejected request, "
  644. "ga_nxt_rsp:\n", ha->host_no));
  645. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gan_data, 16));
  646. rval = QLA_FUNCTION_FAILED;
  647. } else {
  648. /* Populate fc_port_t entry. */
  649. fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
  650. fcport->d_id.b.area = sns_cmd->p.gan_data[18];
  651. fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
  652. memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
  653. memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
  654. if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
  655. sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
  656. fcport->d_id.b.domain = 0xf0;
  657. DEBUG2_3(printk("scsi(%ld): GA_NXT entry - "
  658. "nn %02x%02x%02x%02x%02x%02x%02x%02x "
  659. "pn %02x%02x%02x%02x%02x%02x%02x%02x "
  660. "portid=%02x%02x%02x.\n",
  661. ha->host_no,
  662. fcport->node_name[0], fcport->node_name[1],
  663. fcport->node_name[2], fcport->node_name[3],
  664. fcport->node_name[4], fcport->node_name[5],
  665. fcport->node_name[6], fcport->node_name[7],
  666. fcport->port_name[0], fcport->port_name[1],
  667. fcport->port_name[2], fcport->port_name[3],
  668. fcport->port_name[4], fcport->port_name[5],
  669. fcport->port_name[6], fcport->port_name[7],
  670. fcport->d_id.b.domain, fcport->d_id.b.area,
  671. fcport->d_id.b.al_pa));
  672. }
  673. return (rval);
  674. }
  675. /**
  676. * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
  677. * @ha: HA context
  678. * @list: switch info entries to populate
  679. *
  680. * This command uses the old Exectute SNS Command mailbox routine.
  681. *
  682. * NOTE: Non-Nx_Ports are not requested.
  683. *
  684. * Returns 0 on success.
  685. */
  686. static int
  687. qla2x00_sns_gid_pt(scsi_qla_host_t *ha, sw_info_t *list)
  688. {
  689. int rval;
  690. uint16_t i;
  691. uint8_t *entry;
  692. struct sns_cmd_pkt *sns_cmd;
  693. /* Issue GID_PT. */
  694. /* Prepare SNS command request. */
  695. sns_cmd = qla2x00_prep_sns_cmd(ha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
  696. GID_PT_SNS_DATA_SIZE);
  697. /* Prepare SNS command arguments -- port_type. */
  698. sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
  699. /* Execute SNS command. */
  700. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
  701. sizeof(struct sns_cmd_pkt));
  702. if (rval != QLA_SUCCESS) {
  703. /*EMPTY*/
  704. DEBUG2_3(printk("scsi(%ld): GID_PT Send SNS failed (%d).\n",
  705. ha->host_no, rval));
  706. } else if (sns_cmd->p.gid_data[8] != 0x80 ||
  707. sns_cmd->p.gid_data[9] != 0x02) {
  708. DEBUG2_3(printk("scsi(%ld): GID_PT failed, rejected request, "
  709. "gid_rsp:\n", ha->host_no));
  710. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gid_data, 16));
  711. rval = QLA_FUNCTION_FAILED;
  712. } else {
  713. /* Set port IDs in switch info list. */
  714. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  715. entry = &sns_cmd->p.gid_data[(i * 4) + 16];
  716. list[i].d_id.b.domain = entry[1];
  717. list[i].d_id.b.area = entry[2];
  718. list[i].d_id.b.al_pa = entry[3];
  719. /* Last one exit. */
  720. if (entry[0] & BIT_7) {
  721. list[i].d_id.b.rsvd_1 = entry[0];
  722. break;
  723. }
  724. }
  725. /*
  726. * If we've used all available slots, then the switch is
  727. * reporting back more devices that we can handle with this
  728. * single call. Return a failed status, and let GA_NXT handle
  729. * the overload.
  730. */
  731. if (i == MAX_FIBRE_DEVICES)
  732. rval = QLA_FUNCTION_FAILED;
  733. }
  734. return (rval);
  735. }
  736. /**
  737. * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
  738. * @ha: HA context
  739. * @list: switch info entries to populate
  740. *
  741. * This command uses the old Exectute SNS Command mailbox routine.
  742. *
  743. * Returns 0 on success.
  744. */
  745. static int
  746. qla2x00_sns_gpn_id(scsi_qla_host_t *ha, sw_info_t *list)
  747. {
  748. int rval;
  749. uint16_t i;
  750. struct sns_cmd_pkt *sns_cmd;
  751. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  752. /* Issue GPN_ID */
  753. /* Prepare SNS command request. */
  754. sns_cmd = qla2x00_prep_sns_cmd(ha, GPN_ID_CMD,
  755. GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
  756. /* Prepare SNS command arguments -- port_id. */
  757. sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
  758. sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
  759. sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
  760. /* Execute SNS command. */
  761. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma,
  762. GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
  763. if (rval != QLA_SUCCESS) {
  764. /*EMPTY*/
  765. DEBUG2_3(printk("scsi(%ld): GPN_ID Send SNS failed "
  766. "(%d).\n", ha->host_no, rval));
  767. } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
  768. sns_cmd->p.gpn_data[9] != 0x02) {
  769. DEBUG2_3(printk("scsi(%ld): GPN_ID failed, rejected "
  770. "request, gpn_rsp:\n", ha->host_no));
  771. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gpn_data, 16));
  772. rval = QLA_FUNCTION_FAILED;
  773. } else {
  774. /* Save portname */
  775. memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
  776. WWN_SIZE);
  777. }
  778. /* Last device exit. */
  779. if (list[i].d_id.b.rsvd_1 != 0)
  780. break;
  781. }
  782. return (rval);
  783. }
  784. /**
  785. * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
  786. * @ha: HA context
  787. * @list: switch info entries to populate
  788. *
  789. * This command uses the old Exectute SNS Command mailbox routine.
  790. *
  791. * Returns 0 on success.
  792. */
  793. static int
  794. qla2x00_sns_gnn_id(scsi_qla_host_t *ha, sw_info_t *list)
  795. {
  796. int rval;
  797. uint16_t i;
  798. struct sns_cmd_pkt *sns_cmd;
  799. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  800. /* Issue GNN_ID */
  801. /* Prepare SNS command request. */
  802. sns_cmd = qla2x00_prep_sns_cmd(ha, GNN_ID_CMD,
  803. GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
  804. /* Prepare SNS command arguments -- port_id. */
  805. sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
  806. sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
  807. sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
  808. /* Execute SNS command. */
  809. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma,
  810. GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
  811. if (rval != QLA_SUCCESS) {
  812. /*EMPTY*/
  813. DEBUG2_3(printk("scsi(%ld): GNN_ID Send SNS failed "
  814. "(%d).\n", ha->host_no, rval));
  815. } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
  816. sns_cmd->p.gnn_data[9] != 0x02) {
  817. DEBUG2_3(printk("scsi(%ld): GNN_ID failed, rejected "
  818. "request, gnn_rsp:\n", ha->host_no));
  819. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.gnn_data, 16));
  820. rval = QLA_FUNCTION_FAILED;
  821. } else {
  822. /* Save nodename */
  823. memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16],
  824. WWN_SIZE);
  825. DEBUG2_3(printk("scsi(%ld): GID_PT entry - "
  826. "nn %02x%02x%02x%02x%02x%02x%02x%02x "
  827. "pn %02x%02x%02x%02x%02x%02x%02x%02x "
  828. "portid=%02x%02x%02x.\n",
  829. ha->host_no,
  830. list[i].node_name[0], list[i].node_name[1],
  831. list[i].node_name[2], list[i].node_name[3],
  832. list[i].node_name[4], list[i].node_name[5],
  833. list[i].node_name[6], list[i].node_name[7],
  834. list[i].port_name[0], list[i].port_name[1],
  835. list[i].port_name[2], list[i].port_name[3],
  836. list[i].port_name[4], list[i].port_name[5],
  837. list[i].port_name[6], list[i].port_name[7],
  838. list[i].d_id.b.domain, list[i].d_id.b.area,
  839. list[i].d_id.b.al_pa));
  840. }
  841. /* Last device exit. */
  842. if (list[i].d_id.b.rsvd_1 != 0)
  843. break;
  844. }
  845. return (rval);
  846. }
  847. /**
  848. * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
  849. * @ha: HA context
  850. *
  851. * This command uses the old Exectute SNS Command mailbox routine.
  852. *
  853. * Returns 0 on success.
  854. */
  855. static int
  856. qla2x00_sns_rft_id(scsi_qla_host_t *ha)
  857. {
  858. int rval;
  859. struct sns_cmd_pkt *sns_cmd;
  860. /* Issue RFT_ID. */
  861. /* Prepare SNS command request. */
  862. sns_cmd = qla2x00_prep_sns_cmd(ha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
  863. RFT_ID_SNS_DATA_SIZE);
  864. /* Prepare SNS command arguments -- port_id, FC-4 types */
  865. sns_cmd->p.cmd.param[0] = ha->d_id.b.al_pa;
  866. sns_cmd->p.cmd.param[1] = ha->d_id.b.area;
  867. sns_cmd->p.cmd.param[2] = ha->d_id.b.domain;
  868. sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
  869. /* Execute SNS command. */
  870. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
  871. sizeof(struct sns_cmd_pkt));
  872. if (rval != QLA_SUCCESS) {
  873. /*EMPTY*/
  874. DEBUG2_3(printk("scsi(%ld): RFT_ID Send SNS failed (%d).\n",
  875. ha->host_no, rval));
  876. } else if (sns_cmd->p.rft_data[8] != 0x80 ||
  877. sns_cmd->p.rft_data[9] != 0x02) {
  878. DEBUG2_3(printk("scsi(%ld): RFT_ID failed, rejected request, "
  879. "rft_rsp:\n", ha->host_no));
  880. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.rft_data, 16));
  881. rval = QLA_FUNCTION_FAILED;
  882. } else {
  883. DEBUG2(printk("scsi(%ld): RFT_ID exiting normally.\n",
  884. ha->host_no));
  885. }
  886. return (rval);
  887. }
  888. /**
  889. * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
  890. * HBA.
  891. * @ha: HA context
  892. *
  893. * This command uses the old Exectute SNS Command mailbox routine.
  894. *
  895. * Returns 0 on success.
  896. */
  897. static int
  898. qla2x00_sns_rnn_id(scsi_qla_host_t *ha)
  899. {
  900. int rval;
  901. struct sns_cmd_pkt *sns_cmd;
  902. /* Issue RNN_ID. */
  903. /* Prepare SNS command request. */
  904. sns_cmd = qla2x00_prep_sns_cmd(ha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN,
  905. RNN_ID_SNS_DATA_SIZE);
  906. /* Prepare SNS command arguments -- port_id, nodename. */
  907. sns_cmd->p.cmd.param[0] = ha->d_id.b.al_pa;
  908. sns_cmd->p.cmd.param[1] = ha->d_id.b.area;
  909. sns_cmd->p.cmd.param[2] = ha->d_id.b.domain;
  910. sns_cmd->p.cmd.param[4] = ha->node_name[7];
  911. sns_cmd->p.cmd.param[5] = ha->node_name[6];
  912. sns_cmd->p.cmd.param[6] = ha->node_name[5];
  913. sns_cmd->p.cmd.param[7] = ha->node_name[4];
  914. sns_cmd->p.cmd.param[8] = ha->node_name[3];
  915. sns_cmd->p.cmd.param[9] = ha->node_name[2];
  916. sns_cmd->p.cmd.param[10] = ha->node_name[1];
  917. sns_cmd->p.cmd.param[11] = ha->node_name[0];
  918. /* Execute SNS command. */
  919. rval = qla2x00_send_sns(ha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
  920. sizeof(struct sns_cmd_pkt));
  921. if (rval != QLA_SUCCESS) {
  922. /*EMPTY*/
  923. DEBUG2_3(printk("scsi(%ld): RNN_ID Send SNS failed (%d).\n",
  924. ha->host_no, rval));
  925. } else if (sns_cmd->p.rnn_data[8] != 0x80 ||
  926. sns_cmd->p.rnn_data[9] != 0x02) {
  927. DEBUG2_3(printk("scsi(%ld): RNN_ID failed, rejected request, "
  928. "rnn_rsp:\n", ha->host_no));
  929. DEBUG2_3(qla2x00_dump_buffer(sns_cmd->p.rnn_data, 16));
  930. rval = QLA_FUNCTION_FAILED;
  931. } else {
  932. DEBUG2(printk("scsi(%ld): RNN_ID exiting normally.\n",
  933. ha->host_no));
  934. }
  935. return (rval);
  936. }
  937. /**
  938. * qla2x00_mgmt_svr_login() - Login to fabric Managment Service.
  939. * @ha: HA context
  940. *
  941. * Returns 0 on success.
  942. */
  943. static int
  944. qla2x00_mgmt_svr_login(scsi_qla_host_t *ha)
  945. {
  946. int ret;
  947. uint16_t mb[MAILBOX_REGISTER_COUNT];
  948. ret = QLA_SUCCESS;
  949. if (ha->flags.management_server_logged_in)
  950. return ret;
  951. ha->isp_ops.fabric_login(ha, ha->mgmt_svr_loop_id, 0xff, 0xff, 0xfa,
  952. mb, BIT_1);
  953. if (mb[0] != MBS_COMMAND_COMPLETE) {
  954. DEBUG2_13(printk("%s(%ld): Failed MANAGEMENT_SERVER login: "
  955. "loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x\n",
  956. __func__, ha->host_no, ha->mgmt_svr_loop_id, mb[0], mb[1],
  957. mb[2], mb[6], mb[7]));
  958. ret = QLA_FUNCTION_FAILED;
  959. } else
  960. ha->flags.management_server_logged_in = 1;
  961. return ret;
  962. }
  963. /**
  964. * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
  965. * @ha: HA context
  966. * @req_size: request size in bytes
  967. * @rsp_size: response size in bytes
  968. *
  969. * Returns a pointer to the @ha's ms_iocb.
  970. */
  971. void *
  972. qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size,
  973. uint32_t rsp_size)
  974. {
  975. ms_iocb_entry_t *ms_pkt;
  976. ms_pkt = ha->ms_iocb;
  977. memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
  978. ms_pkt->entry_type = MS_IOCB_TYPE;
  979. ms_pkt->entry_count = 1;
  980. SET_TARGET_ID(ha, ms_pkt->loop_id, ha->mgmt_svr_loop_id);
  981. ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
  982. ms_pkt->timeout = __constant_cpu_to_le16(59);
  983. ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  984. ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
  985. ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
  986. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  987. ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  988. ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  989. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  990. ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  991. ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  992. ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
  993. return ms_pkt;
  994. }
  995. /**
  996. * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
  997. * @ha: HA context
  998. * @req_size: request size in bytes
  999. * @rsp_size: response size in bytes
  1000. *
  1001. * Returns a pointer to the @ha's ms_iocb.
  1002. */
  1003. void *
  1004. qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size,
  1005. uint32_t rsp_size)
  1006. {
  1007. struct ct_entry_24xx *ct_pkt;
  1008. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1009. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  1010. ct_pkt->entry_type = CT_IOCB_TYPE;
  1011. ct_pkt->entry_count = 1;
  1012. ct_pkt->nport_handle = cpu_to_le16(ha->mgmt_svr_loop_id);
  1013. ct_pkt->timeout = __constant_cpu_to_le16(59);
  1014. ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  1015. ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
  1016. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  1017. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1018. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1019. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1020. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1021. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1022. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1023. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  1024. return ct_pkt;
  1025. }
  1026. static inline ms_iocb_entry_t *
  1027. qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size)
  1028. {
  1029. ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
  1030. struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1031. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  1032. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1033. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1034. } else {
  1035. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  1036. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  1037. }
  1038. return ms_pkt;
  1039. }
  1040. /**
  1041. * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
  1042. * @ct_req: CT request buffer
  1043. * @cmd: GS command
  1044. * @rsp_size: response size in bytes
  1045. *
  1046. * Returns a pointer to the intitialized @ct_req.
  1047. */
  1048. static inline struct ct_sns_req *
  1049. qla2x00_prep_ct_fdmi_req(struct ct_sns_req *ct_req, uint16_t cmd,
  1050. uint16_t rsp_size)
  1051. {
  1052. memset(ct_req, 0, sizeof(struct ct_sns_pkt));
  1053. ct_req->header.revision = 0x01;
  1054. ct_req->header.gs_type = 0xFA;
  1055. ct_req->header.gs_subtype = 0x10;
  1056. ct_req->command = cpu_to_be16(cmd);
  1057. ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  1058. return ct_req;
  1059. }
  1060. /**
  1061. * qla2x00_fdmi_rhba() -
  1062. * @ha: HA context
  1063. *
  1064. * Returns 0 on success.
  1065. */
  1066. static int
  1067. qla2x00_fdmi_rhba(scsi_qla_host_t *ha)
  1068. {
  1069. int rval, alen;
  1070. uint32_t size, sn;
  1071. ms_iocb_entry_t *ms_pkt;
  1072. struct ct_sns_req *ct_req;
  1073. struct ct_sns_rsp *ct_rsp;
  1074. uint8_t *entries;
  1075. struct ct_fdmi_hba_attr *eiter;
  1076. /* Issue RHBA */
  1077. /* Prepare common MS IOCB */
  1078. /* Request size adjusted after CT preparation */
  1079. ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RHBA_RSP_SIZE);
  1080. /* Prepare CT request */
  1081. ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RHBA_CMD,
  1082. RHBA_RSP_SIZE);
  1083. ct_rsp = &ha->ct_sns->p.rsp;
  1084. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1085. memcpy(ct_req->req.rhba.hba_identifier, ha->port_name, WWN_SIZE);
  1086. ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
  1087. memcpy(ct_req->req.rhba.port_name, ha->port_name, WWN_SIZE);
  1088. size = 2 * WWN_SIZE + 4 + 4;
  1089. /* Attributes */
  1090. ct_req->req.rhba.attrs.count =
  1091. __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
  1092. entries = ct_req->req.rhba.hba_identifier;
  1093. /* Nodename. */
  1094. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1095. eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
  1096. eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
  1097. memcpy(eiter->a.node_name, ha->node_name, WWN_SIZE);
  1098. size += 4 + WWN_SIZE;
  1099. DEBUG13(printk("%s(%ld): NODENAME=%02x%02x%02x%02x%02x%02x%02x%02x.\n",
  1100. __func__, ha->host_no,
  1101. eiter->a.node_name[0], eiter->a.node_name[1], eiter->a.node_name[2],
  1102. eiter->a.node_name[3], eiter->a.node_name[4], eiter->a.node_name[5],
  1103. eiter->a.node_name[6], eiter->a.node_name[7]));
  1104. /* Manufacturer. */
  1105. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1106. eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
  1107. strcpy(eiter->a.manufacturer, "QLogic Corporation");
  1108. alen = strlen(eiter->a.manufacturer);
  1109. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1110. eiter->len = cpu_to_be16(4 + alen);
  1111. size += 4 + alen;
  1112. DEBUG13(printk("%s(%ld): MANUFACTURER=%s.\n", __func__, ha->host_no,
  1113. eiter->a.manufacturer));
  1114. /* Serial number. */
  1115. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1116. eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
  1117. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  1118. sprintf(eiter->a.serial_num, "%c%05d", 'A' + sn / 100000, sn % 100000);
  1119. alen = strlen(eiter->a.serial_num);
  1120. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1121. eiter->len = cpu_to_be16(4 + alen);
  1122. size += 4 + alen;
  1123. DEBUG13(printk("%s(%ld): SERIALNO=%s.\n", __func__, ha->host_no,
  1124. eiter->a.serial_num));
  1125. /* Model name. */
  1126. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1127. eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
  1128. strcpy(eiter->a.model, ha->model_number);
  1129. alen = strlen(eiter->a.model);
  1130. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1131. eiter->len = cpu_to_be16(4 + alen);
  1132. size += 4 + alen;
  1133. DEBUG13(printk("%s(%ld): MODEL_NAME=%s.\n", __func__, ha->host_no,
  1134. eiter->a.model));
  1135. /* Model description. */
  1136. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1137. eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
  1138. if (ha->model_desc)
  1139. strncpy(eiter->a.model_desc, ha->model_desc, 80);
  1140. alen = strlen(eiter->a.model_desc);
  1141. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1142. eiter->len = cpu_to_be16(4 + alen);
  1143. size += 4 + alen;
  1144. DEBUG13(printk("%s(%ld): MODEL_DESC=%s.\n", __func__, ha->host_no,
  1145. eiter->a.model_desc));
  1146. /* Hardware version. */
  1147. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1148. eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
  1149. strcpy(eiter->a.hw_version, ha->adapter_id);
  1150. alen = strlen(eiter->a.hw_version);
  1151. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1152. eiter->len = cpu_to_be16(4 + alen);
  1153. size += 4 + alen;
  1154. DEBUG13(printk("%s(%ld): HARDWAREVER=%s.\n", __func__, ha->host_no,
  1155. eiter->a.hw_version));
  1156. /* Driver version. */
  1157. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1158. eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
  1159. strcpy(eiter->a.driver_version, qla2x00_version_str);
  1160. alen = strlen(eiter->a.driver_version);
  1161. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1162. eiter->len = cpu_to_be16(4 + alen);
  1163. size += 4 + alen;
  1164. DEBUG13(printk("%s(%ld): DRIVERVER=%s.\n", __func__, ha->host_no,
  1165. eiter->a.driver_version));
  1166. /* Option ROM version. */
  1167. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1168. eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
  1169. strcpy(eiter->a.orom_version, "0.00");
  1170. alen = strlen(eiter->a.orom_version);
  1171. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1172. eiter->len = cpu_to_be16(4 + alen);
  1173. size += 4 + alen;
  1174. DEBUG13(printk("%s(%ld): OPTROMVER=%s.\n", __func__, ha->host_no,
  1175. eiter->a.orom_version));
  1176. /* Firmware version */
  1177. eiter = (struct ct_fdmi_hba_attr *) (entries + size);
  1178. eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
  1179. ha->isp_ops.fw_version_str(ha, eiter->a.fw_version);
  1180. alen = strlen(eiter->a.fw_version);
  1181. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1182. eiter->len = cpu_to_be16(4 + alen);
  1183. size += 4 + alen;
  1184. DEBUG13(printk("%s(%ld): FIRMWAREVER=%s.\n", __func__, ha->host_no,
  1185. eiter->a.fw_version));
  1186. /* Update MS request size. */
  1187. qla2x00_update_ms_fdmi_iocb(ha, size + 16);
  1188. DEBUG13(printk("%s(%ld): RHBA identifier="
  1189. "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
  1190. ha->host_no, ct_req->req.rhba.hba_identifier[0],
  1191. ct_req->req.rhba.hba_identifier[1],
  1192. ct_req->req.rhba.hba_identifier[2],
  1193. ct_req->req.rhba.hba_identifier[3],
  1194. ct_req->req.rhba.hba_identifier[4],
  1195. ct_req->req.rhba.hba_identifier[5],
  1196. ct_req->req.rhba.hba_identifier[6],
  1197. ct_req->req.rhba.hba_identifier[7], size));
  1198. DEBUG13(qla2x00_dump_buffer(entries, size));
  1199. /* Execute MS IOCB */
  1200. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1201. sizeof(ms_iocb_entry_t));
  1202. if (rval != QLA_SUCCESS) {
  1203. /*EMPTY*/
  1204. DEBUG2_3(printk("scsi(%ld): RHBA issue IOCB failed (%d).\n",
  1205. ha->host_no, rval));
  1206. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RHBA") !=
  1207. QLA_SUCCESS) {
  1208. rval = QLA_FUNCTION_FAILED;
  1209. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  1210. ct_rsp->header.explanation_code ==
  1211. CT_EXPL_ALREADY_REGISTERED) {
  1212. DEBUG2_13(printk("%s(%ld): HBA already registered.\n",
  1213. __func__, ha->host_no));
  1214. rval = QLA_ALREADY_REGISTERED;
  1215. }
  1216. } else {
  1217. DEBUG2(printk("scsi(%ld): RHBA exiting normally.\n",
  1218. ha->host_no));
  1219. }
  1220. return rval;
  1221. }
  1222. /**
  1223. * qla2x00_fdmi_dhba() -
  1224. * @ha: HA context
  1225. *
  1226. * Returns 0 on success.
  1227. */
  1228. static int
  1229. qla2x00_fdmi_dhba(scsi_qla_host_t *ha)
  1230. {
  1231. int rval;
  1232. ms_iocb_entry_t *ms_pkt;
  1233. struct ct_sns_req *ct_req;
  1234. struct ct_sns_rsp *ct_rsp;
  1235. /* Issue RPA */
  1236. /* Prepare common MS IOCB */
  1237. ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, DHBA_REQ_SIZE,
  1238. DHBA_RSP_SIZE);
  1239. /* Prepare CT request */
  1240. ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, DHBA_CMD,
  1241. DHBA_RSP_SIZE);
  1242. ct_rsp = &ha->ct_sns->p.rsp;
  1243. /* Prepare FDMI command arguments -- portname. */
  1244. memcpy(ct_req->req.dhba.port_name, ha->port_name, WWN_SIZE);
  1245. DEBUG13(printk("%s(%ld): DHBA portname="
  1246. "%02x%02x%02x%02x%02x%02x%02x%02x.\n", __func__, ha->host_no,
  1247. ct_req->req.dhba.port_name[0], ct_req->req.dhba.port_name[1],
  1248. ct_req->req.dhba.port_name[2], ct_req->req.dhba.port_name[3],
  1249. ct_req->req.dhba.port_name[4], ct_req->req.dhba.port_name[5],
  1250. ct_req->req.dhba.port_name[6], ct_req->req.dhba.port_name[7]));
  1251. /* Execute MS IOCB */
  1252. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1253. sizeof(ms_iocb_entry_t));
  1254. if (rval != QLA_SUCCESS) {
  1255. /*EMPTY*/
  1256. DEBUG2_3(printk("scsi(%ld): DHBA issue IOCB failed (%d).\n",
  1257. ha->host_no, rval));
  1258. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "DHBA") !=
  1259. QLA_SUCCESS) {
  1260. rval = QLA_FUNCTION_FAILED;
  1261. } else {
  1262. DEBUG2(printk("scsi(%ld): DHBA exiting normally.\n",
  1263. ha->host_no));
  1264. }
  1265. return rval;
  1266. }
  1267. /**
  1268. * qla2x00_fdmi_rpa() -
  1269. * @ha: HA context
  1270. *
  1271. * Returns 0 on success.
  1272. */
  1273. static int
  1274. qla2x00_fdmi_rpa(scsi_qla_host_t *ha)
  1275. {
  1276. int rval, alen;
  1277. uint32_t size, max_frame_size;
  1278. ms_iocb_entry_t *ms_pkt;
  1279. struct ct_sns_req *ct_req;
  1280. struct ct_sns_rsp *ct_rsp;
  1281. uint8_t *entries;
  1282. struct ct_fdmi_port_attr *eiter;
  1283. struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
  1284. /* Issue RPA */
  1285. /* Prepare common MS IOCB */
  1286. /* Request size adjusted after CT preparation */
  1287. ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RPA_RSP_SIZE);
  1288. /* Prepare CT request */
  1289. ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RPA_CMD,
  1290. RPA_RSP_SIZE);
  1291. ct_rsp = &ha->ct_sns->p.rsp;
  1292. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1293. memcpy(ct_req->req.rpa.port_name, ha->port_name, WWN_SIZE);
  1294. size = WWN_SIZE + 4;
  1295. /* Attributes */
  1296. ct_req->req.rpa.attrs.count =
  1297. __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
  1298. entries = ct_req->req.rpa.port_name;
  1299. /* FC4 types. */
  1300. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1301. eiter->type = __constant_cpu_to_be16(FDMI_PORT_FC4_TYPES);
  1302. eiter->len = __constant_cpu_to_be16(4 + 32);
  1303. eiter->a.fc4_types[2] = 0x01;
  1304. size += 4 + 32;
  1305. DEBUG13(printk("%s(%ld): FC4_TYPES=%02x %02x.\n", __func__, ha->host_no,
  1306. eiter->a.fc4_types[2], eiter->a.fc4_types[1]));
  1307. /* Supported speed. */
  1308. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1309. eiter->type = __constant_cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
  1310. eiter->len = __constant_cpu_to_be16(4 + 4);
  1311. if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
  1312. eiter->a.sup_speed = __constant_cpu_to_be32(4);
  1313. else if (IS_QLA23XX(ha))
  1314. eiter->a.sup_speed = __constant_cpu_to_be32(2);
  1315. else
  1316. eiter->a.sup_speed = __constant_cpu_to_be32(1);
  1317. size += 4 + 4;
  1318. DEBUG13(printk("%s(%ld): SUPPORTED_SPEED=%x.\n", __func__, ha->host_no,
  1319. eiter->a.sup_speed));
  1320. /* Current speed. */
  1321. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1322. eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
  1323. eiter->len = __constant_cpu_to_be16(4 + 4);
  1324. switch (ha->link_data_rate) {
  1325. case 0:
  1326. eiter->a.cur_speed = __constant_cpu_to_be32(1);
  1327. break;
  1328. case 1:
  1329. eiter->a.cur_speed = __constant_cpu_to_be32(2);
  1330. break;
  1331. case 3:
  1332. eiter->a.cur_speed = __constant_cpu_to_be32(4);
  1333. break;
  1334. }
  1335. size += 4 + 4;
  1336. DEBUG13(printk("%s(%ld): CURRENT_SPEED=%x.\n", __func__, ha->host_no,
  1337. eiter->a.cur_speed));
  1338. /* Max frame size. */
  1339. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1340. eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
  1341. eiter->len = __constant_cpu_to_be16(4 + 4);
  1342. max_frame_size = IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
  1343. (uint32_t) icb24->frame_payload_size:
  1344. (uint32_t) ha->init_cb->frame_payload_size;
  1345. eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
  1346. size += 4 + 4;
  1347. DEBUG13(printk("%s(%ld): MAX_FRAME_SIZE=%x.\n", __func__, ha->host_no,
  1348. eiter->a.max_frame_size));
  1349. /* OS device name. */
  1350. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1351. eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
  1352. sprintf(eiter->a.os_dev_name, "/proc/scsi/qla2xxx/%ld", ha->host_no);
  1353. alen = strlen(eiter->a.os_dev_name);
  1354. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1355. eiter->len = cpu_to_be16(4 + alen);
  1356. size += 4 + alen;
  1357. DEBUG13(printk("%s(%ld): OS_DEVICE_NAME=%s.\n", __func__, ha->host_no,
  1358. eiter->a.os_dev_name));
  1359. /* Hostname. */
  1360. if (strlen(fc_host_system_hostname(ha->host))) {
  1361. eiter = (struct ct_fdmi_port_attr *) (entries + size);
  1362. eiter->type = __constant_cpu_to_be16(FDMI_PORT_HOST_NAME);
  1363. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  1364. "%s", fc_host_system_hostname(ha->host));
  1365. alen = strlen(eiter->a.host_name);
  1366. alen += (alen & 3) ? (4 - (alen & 3)) : 4;
  1367. eiter->len = cpu_to_be16(4 + alen);
  1368. size += 4 + alen;
  1369. DEBUG13(printk("%s(%ld): HOSTNAME=%s.\n", __func__,
  1370. ha->host_no, eiter->a.host_name));
  1371. }
  1372. /* Update MS request size. */
  1373. qla2x00_update_ms_fdmi_iocb(ha, size + 16);
  1374. DEBUG13(printk("%s(%ld): RPA portname="
  1375. "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
  1376. ha->host_no, ct_req->req.rpa.port_name[0],
  1377. ct_req->req.rpa.port_name[1], ct_req->req.rpa.port_name[2],
  1378. ct_req->req.rpa.port_name[3], ct_req->req.rpa.port_name[4],
  1379. ct_req->req.rpa.port_name[5], ct_req->req.rpa.port_name[6],
  1380. ct_req->req.rpa.port_name[7], size));
  1381. DEBUG13(qla2x00_dump_buffer(entries, size));
  1382. /* Execute MS IOCB */
  1383. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1384. sizeof(ms_iocb_entry_t));
  1385. if (rval != QLA_SUCCESS) {
  1386. /*EMPTY*/
  1387. DEBUG2_3(printk("scsi(%ld): RPA issue IOCB failed (%d).\n",
  1388. ha->host_no, rval));
  1389. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RPA") !=
  1390. QLA_SUCCESS) {
  1391. rval = QLA_FUNCTION_FAILED;
  1392. } else {
  1393. DEBUG2(printk("scsi(%ld): RPA exiting normally.\n",
  1394. ha->host_no));
  1395. }
  1396. return rval;
  1397. }
  1398. /**
  1399. * qla2x00_fdmi_register() -
  1400. * @ha: HA context
  1401. *
  1402. * Returns 0 on success.
  1403. */
  1404. int
  1405. qla2x00_fdmi_register(scsi_qla_host_t *ha)
  1406. {
  1407. int rval;
  1408. rval = qla2x00_mgmt_svr_login(ha);
  1409. if (rval)
  1410. return rval;
  1411. rval = qla2x00_fdmi_rhba(ha);
  1412. if (rval) {
  1413. if (rval != QLA_ALREADY_REGISTERED)
  1414. return rval;
  1415. rval = qla2x00_fdmi_dhba(ha);
  1416. if (rval)
  1417. return rval;
  1418. rval = qla2x00_fdmi_rhba(ha);
  1419. if (rval)
  1420. return rval;
  1421. }
  1422. rval = qla2x00_fdmi_rpa(ha);
  1423. return rval;
  1424. }
  1425. /**
  1426. * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
  1427. * @ha: HA context
  1428. * @list: switch info entries to populate
  1429. *
  1430. * Returns 0 on success.
  1431. */
  1432. int
  1433. qla2x00_gfpn_id(scsi_qla_host_t *ha, sw_info_t *list)
  1434. {
  1435. int rval;
  1436. uint16_t i;
  1437. ms_iocb_entry_t *ms_pkt;
  1438. struct ct_sns_req *ct_req;
  1439. struct ct_sns_rsp *ct_rsp;
  1440. if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
  1441. return QLA_FUNCTION_FAILED;
  1442. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  1443. /* Issue GFPN_ID */
  1444. memset(list[i].fabric_port_name, 0, WWN_SIZE);
  1445. /* Prepare common MS IOCB */
  1446. ms_pkt = qla2x00_prep_ms_iocb(ha, GFPN_ID_REQ_SIZE,
  1447. GFPN_ID_RSP_SIZE);
  1448. /* Prepare CT request */
  1449. ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GFPN_ID_CMD,
  1450. GFPN_ID_RSP_SIZE);
  1451. ct_rsp = &ha->ct_sns->p.rsp;
  1452. /* Prepare CT arguments -- port_id */
  1453. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  1454. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  1455. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  1456. /* Execute MS IOCB */
  1457. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1458. sizeof(ms_iocb_entry_t));
  1459. if (rval != QLA_SUCCESS) {
  1460. /*EMPTY*/
  1461. DEBUG2_3(printk("scsi(%ld): GFPN_ID issue IOCB "
  1462. "failed (%d).\n", ha->host_no, rval));
  1463. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
  1464. "GFPN_ID") != QLA_SUCCESS) {
  1465. rval = QLA_FUNCTION_FAILED;
  1466. } else {
  1467. /* Save fabric portname */
  1468. memcpy(list[i].fabric_port_name,
  1469. ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
  1470. }
  1471. /* Last device exit. */
  1472. if (list[i].d_id.b.rsvd_1 != 0)
  1473. break;
  1474. }
  1475. return (rval);
  1476. }
  1477. static inline void *
  1478. qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *ha, uint32_t req_size,
  1479. uint32_t rsp_size)
  1480. {
  1481. struct ct_entry_24xx *ct_pkt;
  1482. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1483. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  1484. ct_pkt->entry_type = CT_IOCB_TYPE;
  1485. ct_pkt->entry_count = 1;
  1486. ct_pkt->nport_handle = cpu_to_le16(ha->mgmt_svr_loop_id);
  1487. ct_pkt->timeout = __constant_cpu_to_le16(59);
  1488. ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
  1489. ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
  1490. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  1491. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1492. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1493. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1494. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1495. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1496. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1497. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  1498. return ct_pkt;
  1499. }
  1500. static inline struct ct_sns_req *
  1501. qla24xx_prep_ct_fm_req(struct ct_sns_req *ct_req, uint16_t cmd,
  1502. uint16_t rsp_size)
  1503. {
  1504. memset(ct_req, 0, sizeof(struct ct_sns_pkt));
  1505. ct_req->header.revision = 0x01;
  1506. ct_req->header.gs_type = 0xFA;
  1507. ct_req->header.gs_subtype = 0x01;
  1508. ct_req->command = cpu_to_be16(cmd);
  1509. ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  1510. return ct_req;
  1511. }
  1512. /**
  1513. * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
  1514. * @ha: HA context
  1515. * @list: switch info entries to populate
  1516. *
  1517. * Returns 0 on success.
  1518. */
  1519. int
  1520. qla2x00_gpsc(scsi_qla_host_t *ha, sw_info_t *list)
  1521. {
  1522. int rval;
  1523. uint16_t i;
  1524. ms_iocb_entry_t *ms_pkt;
  1525. struct ct_sns_req *ct_req;
  1526. struct ct_sns_rsp *ct_rsp;
  1527. if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
  1528. return QLA_FUNCTION_FAILED;
  1529. rval = qla2x00_mgmt_svr_login(ha);
  1530. if (rval)
  1531. return rval;
  1532. for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
  1533. /* Issue GFPN_ID */
  1534. list[i].fp_speeds = list[i].fp_speed = 0;
  1535. /* Prepare common MS IOCB */
  1536. ms_pkt = qla24xx_prep_ms_fm_iocb(ha, GPSC_REQ_SIZE,
  1537. GPSC_RSP_SIZE);
  1538. /* Prepare CT request */
  1539. ct_req = qla24xx_prep_ct_fm_req(&ha->ct_sns->p.req,
  1540. GPSC_CMD, GPSC_RSP_SIZE);
  1541. ct_rsp = &ha->ct_sns->p.rsp;
  1542. /* Prepare CT arguments -- port_name */
  1543. memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
  1544. WWN_SIZE);
  1545. /* Execute MS IOCB */
  1546. rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
  1547. sizeof(ms_iocb_entry_t));
  1548. if (rval != QLA_SUCCESS) {
  1549. /*EMPTY*/
  1550. DEBUG2_3(printk("scsi(%ld): GPSC issue IOCB "
  1551. "failed (%d).\n", ha->host_no, rval));
  1552. } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
  1553. "GPSC") != QLA_SUCCESS) {
  1554. rval = QLA_FUNCTION_FAILED;
  1555. } else {
  1556. /* Save portname */
  1557. list[i].fp_speeds = ct_rsp->rsp.gpsc.speeds;
  1558. list[i].fp_speed = ct_rsp->rsp.gpsc.speed;
  1559. DEBUG2_3(printk("scsi(%ld): GPSC ext entry - "
  1560. "fpn %02x%02x%02x%02x%02x%02x%02x%02x speeds=%04x "
  1561. "speed=%04x.\n", ha->host_no,
  1562. list[i].fabric_port_name[0],
  1563. list[i].fabric_port_name[1],
  1564. list[i].fabric_port_name[2],
  1565. list[i].fabric_port_name[3],
  1566. list[i].fabric_port_name[4],
  1567. list[i].fabric_port_name[5],
  1568. list[i].fabric_port_name[6],
  1569. list[i].fabric_port_name[7],
  1570. be16_to_cpu(list[i].fp_speeds),
  1571. be16_to_cpu(list[i].fp_speed)));
  1572. }
  1573. /* Last device exit. */
  1574. if (list[i].d_id.b.rsvd_1 != 0)
  1575. break;
  1576. }
  1577. return (rval);
  1578. }