qla_gs.c 48 KB

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