qla_attr.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_target.h"
  9. #include <linux/kthread.h>
  10. #include <linux/vmalloc.h>
  11. #include <linux/slab.h>
  12. #include <linux/delay.h>
  13. static int qla24xx_vport_disable(struct fc_vport *, bool);
  14. /* SYSFS attributes --------------------------------------------------------- */
  15. static ssize_t
  16. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  17. struct bin_attribute *bin_attr,
  18. char *buf, loff_t off, size_t count)
  19. {
  20. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  21. struct device, kobj)));
  22. struct qla_hw_data *ha = vha->hw;
  23. int rval = 0;
  24. if (ha->fw_dump_reading == 0)
  25. return 0;
  26. if (IS_QLA82XX(ha)) {
  27. if (off < ha->md_template_size) {
  28. rval = memory_read_from_buffer(buf, count,
  29. &off, ha->md_tmplt_hdr, ha->md_template_size);
  30. return rval;
  31. }
  32. off -= ha->md_template_size;
  33. rval = memory_read_from_buffer(buf, count,
  34. &off, ha->md_dump, ha->md_dump_size);
  35. return rval;
  36. } else
  37. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  38. ha->fw_dump_len);
  39. }
  40. static ssize_t
  41. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  42. struct bin_attribute *bin_attr,
  43. char *buf, loff_t off, size_t count)
  44. {
  45. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  46. struct device, kobj)));
  47. struct qla_hw_data *ha = vha->hw;
  48. int reading;
  49. if (off != 0)
  50. return (0);
  51. reading = simple_strtol(buf, NULL, 10);
  52. switch (reading) {
  53. case 0:
  54. if (!ha->fw_dump_reading)
  55. break;
  56. ql_log(ql_log_info, vha, 0x705d,
  57. "Firmware dump cleared on (%ld).\n", vha->host_no);
  58. if (IS_QLA82XX(vha->hw)) {
  59. qla82xx_md_free(vha);
  60. qla82xx_md_prep(vha);
  61. }
  62. ha->fw_dump_reading = 0;
  63. ha->fw_dumped = 0;
  64. break;
  65. case 1:
  66. if (ha->fw_dumped && !ha->fw_dump_reading) {
  67. ha->fw_dump_reading = 1;
  68. ql_log(ql_log_info, vha, 0x705e,
  69. "Raw firmware dump ready for read on (%ld).\n",
  70. vha->host_no);
  71. }
  72. break;
  73. case 2:
  74. qla2x00_alloc_fw_dump(vha);
  75. break;
  76. case 3:
  77. if (IS_QLA82XX(ha)) {
  78. qla82xx_idc_lock(ha);
  79. qla82xx_set_reset_owner(vha);
  80. qla82xx_idc_unlock(ha);
  81. } else
  82. qla2x00_system_error(vha);
  83. break;
  84. case 4:
  85. if (IS_QLA82XX(ha)) {
  86. if (ha->md_tmplt_hdr)
  87. ql_dbg(ql_dbg_user, vha, 0x705b,
  88. "MiniDump supported with this firmware.\n");
  89. else
  90. ql_dbg(ql_dbg_user, vha, 0x709d,
  91. "MiniDump not supported with this firmware.\n");
  92. }
  93. break;
  94. case 5:
  95. if (IS_QLA82XX(ha))
  96. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  97. break;
  98. }
  99. return count;
  100. }
  101. static struct bin_attribute sysfs_fw_dump_attr = {
  102. .attr = {
  103. .name = "fw_dump",
  104. .mode = S_IRUSR | S_IWUSR,
  105. },
  106. .size = 0,
  107. .read = qla2x00_sysfs_read_fw_dump,
  108. .write = qla2x00_sysfs_write_fw_dump,
  109. };
  110. static ssize_t
  111. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  112. struct bin_attribute *bin_attr,
  113. char *buf, loff_t off, size_t count)
  114. {
  115. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  116. struct device, kobj)));
  117. struct qla_hw_data *ha = vha->hw;
  118. if (!capable(CAP_SYS_ADMIN))
  119. return 0;
  120. if (IS_NOCACHE_VPD_TYPE(ha))
  121. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  122. ha->nvram_size);
  123. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  124. ha->nvram_size);
  125. }
  126. static ssize_t
  127. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  128. struct bin_attribute *bin_attr,
  129. char *buf, loff_t off, size_t count)
  130. {
  131. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  132. struct device, kobj)));
  133. struct qla_hw_data *ha = vha->hw;
  134. uint16_t cnt;
  135. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  136. !ha->isp_ops->write_nvram)
  137. return -EINVAL;
  138. /* Checksum NVRAM. */
  139. if (IS_FWI2_CAPABLE(ha)) {
  140. uint32_t *iter;
  141. uint32_t chksum;
  142. iter = (uint32_t *)buf;
  143. chksum = 0;
  144. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  145. chksum += le32_to_cpu(*iter++);
  146. chksum = ~chksum + 1;
  147. *iter = cpu_to_le32(chksum);
  148. } else {
  149. uint8_t *iter;
  150. uint8_t chksum;
  151. iter = (uint8_t *)buf;
  152. chksum = 0;
  153. for (cnt = 0; cnt < count - 1; cnt++)
  154. chksum += *iter++;
  155. chksum = ~chksum + 1;
  156. *iter = chksum;
  157. }
  158. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  159. ql_log(ql_log_warn, vha, 0x705f,
  160. "HBA not online, failing NVRAM update.\n");
  161. return -EAGAIN;
  162. }
  163. /* Write NVRAM. */
  164. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  165. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  166. count);
  167. ql_dbg(ql_dbg_user, vha, 0x7060,
  168. "Setting ISP_ABORT_NEEDED\n");
  169. /* NVRAM settings take effect immediately. */
  170. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  171. qla2xxx_wake_dpc(vha);
  172. qla2x00_wait_for_chip_reset(vha);
  173. return count;
  174. }
  175. static struct bin_attribute sysfs_nvram_attr = {
  176. .attr = {
  177. .name = "nvram",
  178. .mode = S_IRUSR | S_IWUSR,
  179. },
  180. .size = 512,
  181. .read = qla2x00_sysfs_read_nvram,
  182. .write = qla2x00_sysfs_write_nvram,
  183. };
  184. static ssize_t
  185. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  186. struct bin_attribute *bin_attr,
  187. char *buf, loff_t off, size_t count)
  188. {
  189. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  190. struct device, kobj)));
  191. struct qla_hw_data *ha = vha->hw;
  192. if (ha->optrom_state != QLA_SREADING)
  193. return 0;
  194. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  195. ha->optrom_region_size);
  196. }
  197. static ssize_t
  198. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  199. struct bin_attribute *bin_attr,
  200. char *buf, loff_t off, size_t count)
  201. {
  202. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  203. struct device, kobj)));
  204. struct qla_hw_data *ha = vha->hw;
  205. if (ha->optrom_state != QLA_SWRITING)
  206. return -EINVAL;
  207. if (off > ha->optrom_region_size)
  208. return -ERANGE;
  209. if (off + count > ha->optrom_region_size)
  210. count = ha->optrom_region_size - off;
  211. memcpy(&ha->optrom_buffer[off], buf, count);
  212. return count;
  213. }
  214. static struct bin_attribute sysfs_optrom_attr = {
  215. .attr = {
  216. .name = "optrom",
  217. .mode = S_IRUSR | S_IWUSR,
  218. },
  219. .size = 0,
  220. .read = qla2x00_sysfs_read_optrom,
  221. .write = qla2x00_sysfs_write_optrom,
  222. };
  223. static ssize_t
  224. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  225. struct bin_attribute *bin_attr,
  226. char *buf, loff_t off, size_t count)
  227. {
  228. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  229. struct device, kobj)));
  230. struct qla_hw_data *ha = vha->hw;
  231. uint32_t start = 0;
  232. uint32_t size = ha->optrom_size;
  233. int val, valid;
  234. if (off)
  235. return -EINVAL;
  236. if (unlikely(pci_channel_offline(ha->pdev)))
  237. return -EAGAIN;
  238. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  239. return -EINVAL;
  240. if (start > ha->optrom_size)
  241. return -EINVAL;
  242. switch (val) {
  243. case 0:
  244. if (ha->optrom_state != QLA_SREADING &&
  245. ha->optrom_state != QLA_SWRITING)
  246. return -EINVAL;
  247. ha->optrom_state = QLA_SWAITING;
  248. ql_dbg(ql_dbg_user, vha, 0x7061,
  249. "Freeing flash region allocation -- 0x%x bytes.\n",
  250. ha->optrom_region_size);
  251. vfree(ha->optrom_buffer);
  252. ha->optrom_buffer = NULL;
  253. break;
  254. case 1:
  255. if (ha->optrom_state != QLA_SWAITING)
  256. return -EINVAL;
  257. ha->optrom_region_start = start;
  258. ha->optrom_region_size = start + size > ha->optrom_size ?
  259. ha->optrom_size - start : size;
  260. ha->optrom_state = QLA_SREADING;
  261. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  262. if (ha->optrom_buffer == NULL) {
  263. ql_log(ql_log_warn, vha, 0x7062,
  264. "Unable to allocate memory for optrom retrieval "
  265. "(%x).\n", ha->optrom_region_size);
  266. ha->optrom_state = QLA_SWAITING;
  267. return -ENOMEM;
  268. }
  269. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  270. ql_log(ql_log_warn, vha, 0x7063,
  271. "HBA not online, failing NVRAM update.\n");
  272. return -EAGAIN;
  273. }
  274. ql_dbg(ql_dbg_user, vha, 0x7064,
  275. "Reading flash region -- 0x%x/0x%x.\n",
  276. ha->optrom_region_start, ha->optrom_region_size);
  277. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  278. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  279. ha->optrom_region_start, ha->optrom_region_size);
  280. break;
  281. case 2:
  282. if (ha->optrom_state != QLA_SWAITING)
  283. return -EINVAL;
  284. /*
  285. * We need to be more restrictive on which FLASH regions are
  286. * allowed to be updated via user-space. Regions accessible
  287. * via this method include:
  288. *
  289. * ISP21xx/ISP22xx/ISP23xx type boards:
  290. *
  291. * 0x000000 -> 0x020000 -- Boot code.
  292. *
  293. * ISP2322/ISP24xx type boards:
  294. *
  295. * 0x000000 -> 0x07ffff -- Boot code.
  296. * 0x080000 -> 0x0fffff -- Firmware.
  297. *
  298. * ISP25xx type boards:
  299. *
  300. * 0x000000 -> 0x07ffff -- Boot code.
  301. * 0x080000 -> 0x0fffff -- Firmware.
  302. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  303. */
  304. valid = 0;
  305. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  306. valid = 1;
  307. else if (start == (ha->flt_region_boot * 4) ||
  308. start == (ha->flt_region_fw * 4))
  309. valid = 1;
  310. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
  311. || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
  312. valid = 1;
  313. if (!valid) {
  314. ql_log(ql_log_warn, vha, 0x7065,
  315. "Invalid start region 0x%x/0x%x.\n", start, size);
  316. return -EINVAL;
  317. }
  318. ha->optrom_region_start = start;
  319. ha->optrom_region_size = start + size > ha->optrom_size ?
  320. ha->optrom_size - start : size;
  321. ha->optrom_state = QLA_SWRITING;
  322. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  323. if (ha->optrom_buffer == NULL) {
  324. ql_log(ql_log_warn, vha, 0x7066,
  325. "Unable to allocate memory for optrom update "
  326. "(%x)\n", ha->optrom_region_size);
  327. ha->optrom_state = QLA_SWAITING;
  328. return -ENOMEM;
  329. }
  330. ql_dbg(ql_dbg_user, vha, 0x7067,
  331. "Staging flash region write -- 0x%x/0x%x.\n",
  332. ha->optrom_region_start, ha->optrom_region_size);
  333. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  334. break;
  335. case 3:
  336. if (ha->optrom_state != QLA_SWRITING)
  337. return -EINVAL;
  338. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  339. ql_log(ql_log_warn, vha, 0x7068,
  340. "HBA not online, failing flash update.\n");
  341. return -EAGAIN;
  342. }
  343. ql_dbg(ql_dbg_user, vha, 0x7069,
  344. "Writing flash region -- 0x%x/0x%x.\n",
  345. ha->optrom_region_start, ha->optrom_region_size);
  346. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  347. ha->optrom_region_start, ha->optrom_region_size);
  348. break;
  349. default:
  350. return -EINVAL;
  351. }
  352. return count;
  353. }
  354. static struct bin_attribute sysfs_optrom_ctl_attr = {
  355. .attr = {
  356. .name = "optrom_ctl",
  357. .mode = S_IWUSR,
  358. },
  359. .size = 0,
  360. .write = qla2x00_sysfs_write_optrom_ctl,
  361. };
  362. static ssize_t
  363. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  364. struct bin_attribute *bin_attr,
  365. char *buf, loff_t off, size_t count)
  366. {
  367. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  368. struct device, kobj)));
  369. struct qla_hw_data *ha = vha->hw;
  370. if (unlikely(pci_channel_offline(ha->pdev)))
  371. return -EAGAIN;
  372. if (!capable(CAP_SYS_ADMIN))
  373. return -EINVAL;
  374. if (IS_NOCACHE_VPD_TYPE(ha))
  375. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  376. ha->vpd_size);
  377. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  378. }
  379. static ssize_t
  380. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  381. struct bin_attribute *bin_attr,
  382. char *buf, loff_t off, size_t count)
  383. {
  384. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  385. struct device, kobj)));
  386. struct qla_hw_data *ha = vha->hw;
  387. uint8_t *tmp_data;
  388. if (unlikely(pci_channel_offline(ha->pdev)))
  389. return 0;
  390. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  391. !ha->isp_ops->write_nvram)
  392. return 0;
  393. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  394. ql_log(ql_log_warn, vha, 0x706a,
  395. "HBA not online, failing VPD update.\n");
  396. return -EAGAIN;
  397. }
  398. /* Write NVRAM. */
  399. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  400. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  401. /* Update flash version information for 4Gb & above. */
  402. if (!IS_FWI2_CAPABLE(ha))
  403. return -EINVAL;
  404. tmp_data = vmalloc(256);
  405. if (!tmp_data) {
  406. ql_log(ql_log_warn, vha, 0x706b,
  407. "Unable to allocate memory for VPD information update.\n");
  408. return -ENOMEM;
  409. }
  410. ha->isp_ops->get_flash_version(vha, tmp_data);
  411. vfree(tmp_data);
  412. return count;
  413. }
  414. static struct bin_attribute sysfs_vpd_attr = {
  415. .attr = {
  416. .name = "vpd",
  417. .mode = S_IRUSR | S_IWUSR,
  418. },
  419. .size = 0,
  420. .read = qla2x00_sysfs_read_vpd,
  421. .write = qla2x00_sysfs_write_vpd,
  422. };
  423. static ssize_t
  424. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  425. struct bin_attribute *bin_attr,
  426. char *buf, loff_t off, size_t count)
  427. {
  428. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  429. struct device, kobj)));
  430. struct qla_hw_data *ha = vha->hw;
  431. uint16_t iter, addr, offset;
  432. int rval;
  433. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  434. return 0;
  435. if (ha->sfp_data)
  436. goto do_read;
  437. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  438. &ha->sfp_data_dma);
  439. if (!ha->sfp_data) {
  440. ql_log(ql_log_warn, vha, 0x706c,
  441. "Unable to allocate memory for SFP read-data.\n");
  442. return 0;
  443. }
  444. do_read:
  445. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  446. addr = 0xa0;
  447. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  448. iter++, offset += SFP_BLOCK_SIZE) {
  449. if (iter == 4) {
  450. /* Skip to next device address. */
  451. addr = 0xa2;
  452. offset = 0;
  453. }
  454. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
  455. addr, offset, SFP_BLOCK_SIZE, 0);
  456. if (rval != QLA_SUCCESS) {
  457. ql_log(ql_log_warn, vha, 0x706d,
  458. "Unable to read SFP data (%x/%x/%x).\n", rval,
  459. addr, offset);
  460. return -EIO;
  461. }
  462. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  463. buf += SFP_BLOCK_SIZE;
  464. }
  465. return count;
  466. }
  467. static struct bin_attribute sysfs_sfp_attr = {
  468. .attr = {
  469. .name = "sfp",
  470. .mode = S_IRUSR | S_IWUSR,
  471. },
  472. .size = SFP_DEV_SIZE * 2,
  473. .read = qla2x00_sysfs_read_sfp,
  474. };
  475. static ssize_t
  476. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  477. struct bin_attribute *bin_attr,
  478. char *buf, loff_t off, size_t count)
  479. {
  480. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  481. struct device, kobj)));
  482. struct qla_hw_data *ha = vha->hw;
  483. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  484. int type;
  485. if (off != 0)
  486. return -EINVAL;
  487. type = simple_strtol(buf, NULL, 10);
  488. switch (type) {
  489. case 0x2025c:
  490. ql_log(ql_log_info, vha, 0x706e,
  491. "Issuing ISP reset.\n");
  492. scsi_block_requests(vha->host);
  493. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  494. if (IS_QLA82XX(ha)) {
  495. ha->flags.isp82xx_no_md_cap = 1;
  496. qla82xx_idc_lock(ha);
  497. qla82xx_set_reset_owner(vha);
  498. qla82xx_idc_unlock(ha);
  499. }
  500. qla2xxx_wake_dpc(vha);
  501. qla2x00_wait_for_chip_reset(vha);
  502. scsi_unblock_requests(vha->host);
  503. break;
  504. case 0x2025d:
  505. if (!IS_QLA81XX(ha) || !IS_QLA8031(ha))
  506. return -EPERM;
  507. ql_log(ql_log_info, vha, 0x706f,
  508. "Issuing MPI reset.\n");
  509. /* Make sure FC side is not in reset */
  510. qla2x00_wait_for_hba_online(vha);
  511. /* Issue MPI reset */
  512. scsi_block_requests(vha->host);
  513. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  514. ql_log(ql_log_warn, vha, 0x7070,
  515. "MPI reset failed.\n");
  516. scsi_unblock_requests(vha->host);
  517. break;
  518. case 0x2025e:
  519. if (!IS_QLA82XX(ha) || vha != base_vha) {
  520. ql_log(ql_log_info, vha, 0x7071,
  521. "FCoE ctx reset no supported.\n");
  522. return -EPERM;
  523. }
  524. ql_log(ql_log_info, vha, 0x7072,
  525. "Issuing FCoE ctx reset.\n");
  526. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  527. qla2xxx_wake_dpc(vha);
  528. qla2x00_wait_for_fcoe_ctx_reset(vha);
  529. break;
  530. }
  531. return count;
  532. }
  533. static struct bin_attribute sysfs_reset_attr = {
  534. .attr = {
  535. .name = "reset",
  536. .mode = S_IWUSR,
  537. },
  538. .size = 0,
  539. .write = qla2x00_sysfs_write_reset,
  540. };
  541. static ssize_t
  542. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  543. struct bin_attribute *bin_attr,
  544. char *buf, loff_t off, size_t count)
  545. {
  546. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  547. struct device, kobj)));
  548. struct qla_hw_data *ha = vha->hw;
  549. int rval;
  550. uint16_t actual_size;
  551. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  552. return 0;
  553. if (ha->xgmac_data)
  554. goto do_read;
  555. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  556. &ha->xgmac_data_dma, GFP_KERNEL);
  557. if (!ha->xgmac_data) {
  558. ql_log(ql_log_warn, vha, 0x7076,
  559. "Unable to allocate memory for XGMAC read-data.\n");
  560. return 0;
  561. }
  562. do_read:
  563. actual_size = 0;
  564. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  565. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  566. XGMAC_DATA_SIZE, &actual_size);
  567. if (rval != QLA_SUCCESS) {
  568. ql_log(ql_log_warn, vha, 0x7077,
  569. "Unable to read XGMAC data (%x).\n", rval);
  570. count = 0;
  571. }
  572. count = actual_size > count ? count: actual_size;
  573. memcpy(buf, ha->xgmac_data, count);
  574. return count;
  575. }
  576. static struct bin_attribute sysfs_xgmac_stats_attr = {
  577. .attr = {
  578. .name = "xgmac_stats",
  579. .mode = S_IRUSR,
  580. },
  581. .size = 0,
  582. .read = qla2x00_sysfs_read_xgmac_stats,
  583. };
  584. static ssize_t
  585. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  586. struct bin_attribute *bin_attr,
  587. char *buf, loff_t off, size_t count)
  588. {
  589. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  590. struct device, kobj)));
  591. struct qla_hw_data *ha = vha->hw;
  592. int rval;
  593. uint16_t actual_size;
  594. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  595. return 0;
  596. if (ha->dcbx_tlv)
  597. goto do_read;
  598. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  599. &ha->dcbx_tlv_dma, GFP_KERNEL);
  600. if (!ha->dcbx_tlv) {
  601. ql_log(ql_log_warn, vha, 0x7078,
  602. "Unable to allocate memory for DCBX TLV read-data.\n");
  603. return -ENOMEM;
  604. }
  605. do_read:
  606. actual_size = 0;
  607. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  608. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  609. DCBX_TLV_DATA_SIZE);
  610. if (rval != QLA_SUCCESS) {
  611. ql_log(ql_log_warn, vha, 0x7079,
  612. "Unable to read DCBX TLV (%x).\n", rval);
  613. return -EIO;
  614. }
  615. memcpy(buf, ha->dcbx_tlv, count);
  616. return count;
  617. }
  618. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  619. .attr = {
  620. .name = "dcbx_tlv",
  621. .mode = S_IRUSR,
  622. },
  623. .size = 0,
  624. .read = qla2x00_sysfs_read_dcbx_tlv,
  625. };
  626. static struct sysfs_entry {
  627. char *name;
  628. struct bin_attribute *attr;
  629. int is4GBp_only;
  630. } bin_file_entries[] = {
  631. { "fw_dump", &sysfs_fw_dump_attr, },
  632. { "nvram", &sysfs_nvram_attr, },
  633. { "optrom", &sysfs_optrom_attr, },
  634. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  635. { "vpd", &sysfs_vpd_attr, 1 },
  636. { "sfp", &sysfs_sfp_attr, 1 },
  637. { "reset", &sysfs_reset_attr, },
  638. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  639. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  640. { NULL },
  641. };
  642. void
  643. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  644. {
  645. struct Scsi_Host *host = vha->host;
  646. struct sysfs_entry *iter;
  647. int ret;
  648. for (iter = bin_file_entries; iter->name; iter++) {
  649. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  650. continue;
  651. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  652. continue;
  653. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  654. continue;
  655. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  656. iter->attr);
  657. if (ret)
  658. ql_log(ql_log_warn, vha, 0x00f3,
  659. "Unable to create sysfs %s binary attribute (%d).\n",
  660. iter->name, ret);
  661. else
  662. ql_dbg(ql_dbg_init, vha, 0x00f4,
  663. "Successfully created sysfs %s binary attribure.\n",
  664. iter->name);
  665. }
  666. }
  667. void
  668. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  669. {
  670. struct Scsi_Host *host = vha->host;
  671. struct sysfs_entry *iter;
  672. struct qla_hw_data *ha = vha->hw;
  673. for (iter = bin_file_entries; iter->name; iter++) {
  674. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  675. continue;
  676. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  677. continue;
  678. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  679. continue;
  680. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  681. iter->attr);
  682. }
  683. if (ha->beacon_blink_led == 1)
  684. ha->isp_ops->beacon_off(vha);
  685. }
  686. /* Scsi_Host attributes. */
  687. static ssize_t
  688. qla2x00_drvr_version_show(struct device *dev,
  689. struct device_attribute *attr, char *buf)
  690. {
  691. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  692. }
  693. static ssize_t
  694. qla2x00_fw_version_show(struct device *dev,
  695. struct device_attribute *attr, char *buf)
  696. {
  697. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  698. struct qla_hw_data *ha = vha->hw;
  699. char fw_str[128];
  700. return snprintf(buf, PAGE_SIZE, "%s\n",
  701. ha->isp_ops->fw_version_str(vha, fw_str));
  702. }
  703. static ssize_t
  704. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  705. char *buf)
  706. {
  707. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  708. struct qla_hw_data *ha = vha->hw;
  709. uint32_t sn;
  710. if (IS_FWI2_CAPABLE(ha)) {
  711. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  712. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  713. }
  714. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  715. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  716. sn % 100000);
  717. }
  718. static ssize_t
  719. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  720. char *buf)
  721. {
  722. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  723. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  724. }
  725. static ssize_t
  726. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  727. char *buf)
  728. {
  729. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  730. struct qla_hw_data *ha = vha->hw;
  731. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  732. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  733. ha->product_id[3]);
  734. }
  735. static ssize_t
  736. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  737. char *buf)
  738. {
  739. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  740. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  741. }
  742. static ssize_t
  743. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  744. char *buf)
  745. {
  746. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  747. return snprintf(buf, PAGE_SIZE, "%s\n",
  748. vha->hw->model_desc ? vha->hw->model_desc : "");
  749. }
  750. static ssize_t
  751. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  752. char *buf)
  753. {
  754. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  755. char pci_info[30];
  756. return snprintf(buf, PAGE_SIZE, "%s\n",
  757. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  758. }
  759. static ssize_t
  760. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  761. char *buf)
  762. {
  763. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  764. struct qla_hw_data *ha = vha->hw;
  765. int len = 0;
  766. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  767. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  768. vha->device_flags & DFLG_NO_CABLE)
  769. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  770. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  771. qla2x00_reset_active(vha))
  772. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  773. else {
  774. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  775. switch (ha->current_topology) {
  776. case ISP_CFG_NL:
  777. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  778. break;
  779. case ISP_CFG_FL:
  780. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  781. break;
  782. case ISP_CFG_N:
  783. len += snprintf(buf + len, PAGE_SIZE-len,
  784. "N_Port to N_Port\n");
  785. break;
  786. case ISP_CFG_F:
  787. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  788. break;
  789. default:
  790. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  791. break;
  792. }
  793. }
  794. return len;
  795. }
  796. static ssize_t
  797. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  798. char *buf)
  799. {
  800. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  801. int len = 0;
  802. switch (vha->hw->zio_mode) {
  803. case QLA_ZIO_MODE_6:
  804. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  805. break;
  806. case QLA_ZIO_DISABLED:
  807. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  808. break;
  809. }
  810. return len;
  811. }
  812. static ssize_t
  813. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  814. const char *buf, size_t count)
  815. {
  816. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  817. struct qla_hw_data *ha = vha->hw;
  818. int val = 0;
  819. uint16_t zio_mode;
  820. if (!IS_ZIO_SUPPORTED(ha))
  821. return -ENOTSUPP;
  822. if (sscanf(buf, "%d", &val) != 1)
  823. return -EINVAL;
  824. if (val)
  825. zio_mode = QLA_ZIO_MODE_6;
  826. else
  827. zio_mode = QLA_ZIO_DISABLED;
  828. /* Update per-hba values and queue a reset. */
  829. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  830. ha->zio_mode = zio_mode;
  831. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  832. }
  833. return strlen(buf);
  834. }
  835. static ssize_t
  836. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  837. char *buf)
  838. {
  839. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  840. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  841. }
  842. static ssize_t
  843. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  844. const char *buf, size_t count)
  845. {
  846. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  847. int val = 0;
  848. uint16_t zio_timer;
  849. if (sscanf(buf, "%d", &val) != 1)
  850. return -EINVAL;
  851. if (val > 25500 || val < 100)
  852. return -ERANGE;
  853. zio_timer = (uint16_t)(val / 100);
  854. vha->hw->zio_timer = zio_timer;
  855. return strlen(buf);
  856. }
  857. static ssize_t
  858. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  859. char *buf)
  860. {
  861. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  862. int len = 0;
  863. if (vha->hw->beacon_blink_led)
  864. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  865. else
  866. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  867. return len;
  868. }
  869. static ssize_t
  870. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  871. const char *buf, size_t count)
  872. {
  873. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  874. struct qla_hw_data *ha = vha->hw;
  875. int val = 0;
  876. int rval;
  877. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  878. return -EPERM;
  879. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  880. ql_log(ql_log_warn, vha, 0x707a,
  881. "Abort ISP active -- ignoring beacon request.\n");
  882. return -EBUSY;
  883. }
  884. if (sscanf(buf, "%d", &val) != 1)
  885. return -EINVAL;
  886. if (val)
  887. rval = ha->isp_ops->beacon_on(vha);
  888. else
  889. rval = ha->isp_ops->beacon_off(vha);
  890. if (rval != QLA_SUCCESS)
  891. count = 0;
  892. return count;
  893. }
  894. static ssize_t
  895. qla2x00_optrom_bios_version_show(struct device *dev,
  896. struct device_attribute *attr, char *buf)
  897. {
  898. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  899. struct qla_hw_data *ha = vha->hw;
  900. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  901. ha->bios_revision[0]);
  902. }
  903. static ssize_t
  904. qla2x00_optrom_efi_version_show(struct device *dev,
  905. struct device_attribute *attr, char *buf)
  906. {
  907. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  908. struct qla_hw_data *ha = vha->hw;
  909. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  910. ha->efi_revision[0]);
  911. }
  912. static ssize_t
  913. qla2x00_optrom_fcode_version_show(struct device *dev,
  914. struct device_attribute *attr, char *buf)
  915. {
  916. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  917. struct qla_hw_data *ha = vha->hw;
  918. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  919. ha->fcode_revision[0]);
  920. }
  921. static ssize_t
  922. qla2x00_optrom_fw_version_show(struct device *dev,
  923. struct device_attribute *attr, char *buf)
  924. {
  925. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  926. struct qla_hw_data *ha = vha->hw;
  927. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  928. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  929. ha->fw_revision[3]);
  930. }
  931. static ssize_t
  932. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  933. struct device_attribute *attr, char *buf)
  934. {
  935. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  936. struct qla_hw_data *ha = vha->hw;
  937. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  938. return snprintf(buf, PAGE_SIZE, "\n");
  939. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  940. ha->gold_fw_version[0], ha->gold_fw_version[1],
  941. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  942. }
  943. static ssize_t
  944. qla2x00_total_isp_aborts_show(struct device *dev,
  945. struct device_attribute *attr, char *buf)
  946. {
  947. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  948. return snprintf(buf, PAGE_SIZE, "%d\n",
  949. vha->qla_stats.total_isp_aborts);
  950. }
  951. static ssize_t
  952. qla24xx_84xx_fw_version_show(struct device *dev,
  953. struct device_attribute *attr, char *buf)
  954. {
  955. int rval = QLA_SUCCESS;
  956. uint16_t status[2] = {0, 0};
  957. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  958. struct qla_hw_data *ha = vha->hw;
  959. if (!IS_QLA84XX(ha))
  960. return snprintf(buf, PAGE_SIZE, "\n");
  961. if (ha->cs84xx->op_fw_version == 0)
  962. rval = qla84xx_verify_chip(vha, status);
  963. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  964. return snprintf(buf, PAGE_SIZE, "%u\n",
  965. (uint32_t)ha->cs84xx->op_fw_version);
  966. return snprintf(buf, PAGE_SIZE, "\n");
  967. }
  968. static ssize_t
  969. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  970. char *buf)
  971. {
  972. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  973. struct qla_hw_data *ha = vha->hw;
  974. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  975. return snprintf(buf, PAGE_SIZE, "\n");
  976. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  977. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  978. ha->mpi_capabilities);
  979. }
  980. static ssize_t
  981. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  982. char *buf)
  983. {
  984. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  985. struct qla_hw_data *ha = vha->hw;
  986. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  987. return snprintf(buf, PAGE_SIZE, "\n");
  988. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  989. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  990. }
  991. static ssize_t
  992. qla2x00_flash_block_size_show(struct device *dev,
  993. struct device_attribute *attr, char *buf)
  994. {
  995. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  996. struct qla_hw_data *ha = vha->hw;
  997. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  998. }
  999. static ssize_t
  1000. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1001. char *buf)
  1002. {
  1003. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1004. if (!IS_CNA_CAPABLE(vha->hw))
  1005. return snprintf(buf, PAGE_SIZE, "\n");
  1006. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1007. }
  1008. static ssize_t
  1009. qla2x00_vn_port_mac_address_show(struct device *dev,
  1010. struct device_attribute *attr, char *buf)
  1011. {
  1012. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1013. if (!IS_CNA_CAPABLE(vha->hw))
  1014. return snprintf(buf, PAGE_SIZE, "\n");
  1015. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1016. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1017. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1018. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1019. }
  1020. static ssize_t
  1021. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1022. char *buf)
  1023. {
  1024. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1025. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1026. }
  1027. static ssize_t
  1028. qla2x00_thermal_temp_show(struct device *dev,
  1029. struct device_attribute *attr, char *buf)
  1030. {
  1031. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1032. int rval = QLA_FUNCTION_FAILED;
  1033. uint16_t temp, frac;
  1034. if (!vha->hw->flags.thermal_supported)
  1035. return snprintf(buf, PAGE_SIZE, "\n");
  1036. temp = frac = 0;
  1037. if (qla2x00_reset_active(vha))
  1038. ql_log(ql_log_warn, vha, 0x707b,
  1039. "ISP reset active.\n");
  1040. else if (!vha->hw->flags.eeh_busy)
  1041. rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
  1042. if (rval != QLA_SUCCESS)
  1043. return snprintf(buf, PAGE_SIZE, "\n");
  1044. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
  1045. }
  1046. static ssize_t
  1047. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1048. char *buf)
  1049. {
  1050. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1051. int rval = QLA_FUNCTION_FAILED;
  1052. uint16_t state[5];
  1053. if (qla2x00_reset_active(vha))
  1054. ql_log(ql_log_warn, vha, 0x707c,
  1055. "ISP reset active.\n");
  1056. else if (!vha->hw->flags.eeh_busy)
  1057. rval = qla2x00_get_firmware_state(vha, state);
  1058. if (rval != QLA_SUCCESS)
  1059. memset(state, -1, sizeof(state));
  1060. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1061. state[1], state[2], state[3], state[4]);
  1062. }
  1063. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1064. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1065. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1066. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1067. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1068. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1069. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1070. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1071. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1072. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1073. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1074. qla2x00_zio_timer_store);
  1075. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1076. qla2x00_beacon_store);
  1077. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1078. qla2x00_optrom_bios_version_show, NULL);
  1079. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1080. qla2x00_optrom_efi_version_show, NULL);
  1081. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1082. qla2x00_optrom_fcode_version_show, NULL);
  1083. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1084. NULL);
  1085. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1086. qla2x00_optrom_gold_fw_version_show, NULL);
  1087. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1088. NULL);
  1089. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1090. NULL);
  1091. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1092. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1093. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1094. NULL);
  1095. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1096. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1097. qla2x00_vn_port_mac_address_show, NULL);
  1098. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1099. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1100. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1101. struct device_attribute *qla2x00_host_attrs[] = {
  1102. &dev_attr_driver_version,
  1103. &dev_attr_fw_version,
  1104. &dev_attr_serial_num,
  1105. &dev_attr_isp_name,
  1106. &dev_attr_isp_id,
  1107. &dev_attr_model_name,
  1108. &dev_attr_model_desc,
  1109. &dev_attr_pci_info,
  1110. &dev_attr_link_state,
  1111. &dev_attr_zio,
  1112. &dev_attr_zio_timer,
  1113. &dev_attr_beacon,
  1114. &dev_attr_optrom_bios_version,
  1115. &dev_attr_optrom_efi_version,
  1116. &dev_attr_optrom_fcode_version,
  1117. &dev_attr_optrom_fw_version,
  1118. &dev_attr_84xx_fw_version,
  1119. &dev_attr_total_isp_aborts,
  1120. &dev_attr_mpi_version,
  1121. &dev_attr_phy_version,
  1122. &dev_attr_flash_block_size,
  1123. &dev_attr_vlan_id,
  1124. &dev_attr_vn_port_mac_address,
  1125. &dev_attr_fabric_param,
  1126. &dev_attr_fw_state,
  1127. &dev_attr_optrom_gold_fw_version,
  1128. &dev_attr_thermal_temp,
  1129. NULL,
  1130. };
  1131. /* Host attributes. */
  1132. static void
  1133. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1134. {
  1135. scsi_qla_host_t *vha = shost_priv(shost);
  1136. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1137. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1138. }
  1139. static void
  1140. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1141. {
  1142. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1143. (shost_priv(shost)))->hw;
  1144. u32 speed = FC_PORTSPEED_UNKNOWN;
  1145. switch (ha->link_data_rate) {
  1146. case PORT_SPEED_1GB:
  1147. speed = FC_PORTSPEED_1GBIT;
  1148. break;
  1149. case PORT_SPEED_2GB:
  1150. speed = FC_PORTSPEED_2GBIT;
  1151. break;
  1152. case PORT_SPEED_4GB:
  1153. speed = FC_PORTSPEED_4GBIT;
  1154. break;
  1155. case PORT_SPEED_8GB:
  1156. speed = FC_PORTSPEED_8GBIT;
  1157. break;
  1158. case PORT_SPEED_10GB:
  1159. speed = FC_PORTSPEED_10GBIT;
  1160. break;
  1161. case PORT_SPEED_16GB:
  1162. speed = FC_PORTSPEED_16GBIT;
  1163. break;
  1164. }
  1165. fc_host_speed(shost) = speed;
  1166. }
  1167. static void
  1168. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1169. {
  1170. scsi_qla_host_t *vha = shost_priv(shost);
  1171. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1172. if (vha->vp_idx) {
  1173. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1174. return;
  1175. }
  1176. switch (vha->hw->current_topology) {
  1177. case ISP_CFG_NL:
  1178. port_type = FC_PORTTYPE_LPORT;
  1179. break;
  1180. case ISP_CFG_FL:
  1181. port_type = FC_PORTTYPE_NLPORT;
  1182. break;
  1183. case ISP_CFG_N:
  1184. port_type = FC_PORTTYPE_PTP;
  1185. break;
  1186. case ISP_CFG_F:
  1187. port_type = FC_PORTTYPE_NPORT;
  1188. break;
  1189. }
  1190. fc_host_port_type(shost) = port_type;
  1191. }
  1192. static void
  1193. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1194. {
  1195. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1196. scsi_qla_host_t *vha = shost_priv(host);
  1197. fc_port_t *fcport;
  1198. u64 node_name = 0;
  1199. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1200. if (fcport->rport &&
  1201. starget->id == fcport->rport->scsi_target_id) {
  1202. node_name = wwn_to_u64(fcport->node_name);
  1203. break;
  1204. }
  1205. }
  1206. fc_starget_node_name(starget) = node_name;
  1207. }
  1208. static void
  1209. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1210. {
  1211. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1212. scsi_qla_host_t *vha = shost_priv(host);
  1213. fc_port_t *fcport;
  1214. u64 port_name = 0;
  1215. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1216. if (fcport->rport &&
  1217. starget->id == fcport->rport->scsi_target_id) {
  1218. port_name = wwn_to_u64(fcport->port_name);
  1219. break;
  1220. }
  1221. }
  1222. fc_starget_port_name(starget) = port_name;
  1223. }
  1224. static void
  1225. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1226. {
  1227. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1228. scsi_qla_host_t *vha = shost_priv(host);
  1229. fc_port_t *fcport;
  1230. uint32_t port_id = ~0U;
  1231. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1232. if (fcport->rport &&
  1233. starget->id == fcport->rport->scsi_target_id) {
  1234. port_id = fcport->d_id.b.domain << 16 |
  1235. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1236. break;
  1237. }
  1238. }
  1239. fc_starget_port_id(starget) = port_id;
  1240. }
  1241. static void
  1242. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1243. {
  1244. if (timeout)
  1245. rport->dev_loss_tmo = timeout;
  1246. else
  1247. rport->dev_loss_tmo = 1;
  1248. }
  1249. static void
  1250. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1251. {
  1252. struct Scsi_Host *host = rport_to_shost(rport);
  1253. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1254. unsigned long flags;
  1255. if (!fcport)
  1256. return;
  1257. /* Now that the rport has been deleted, set the fcport state to
  1258. FCS_DEVICE_DEAD */
  1259. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1260. /*
  1261. * Transport has effectively 'deleted' the rport, clear
  1262. * all local references.
  1263. */
  1264. spin_lock_irqsave(host->host_lock, flags);
  1265. fcport->rport = fcport->drport = NULL;
  1266. *((fc_port_t **)rport->dd_data) = NULL;
  1267. spin_unlock_irqrestore(host->host_lock, flags);
  1268. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1269. return;
  1270. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1271. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1272. return;
  1273. }
  1274. }
  1275. static void
  1276. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1277. {
  1278. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1279. if (!fcport)
  1280. return;
  1281. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1282. return;
  1283. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1284. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1285. return;
  1286. }
  1287. /*
  1288. * At this point all fcport's software-states are cleared. Perform any
  1289. * final cleanup of firmware resources (PCBs and XCBs).
  1290. */
  1291. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1292. !test_bit(UNLOADING, &fcport->vha->dpc_flags)) {
  1293. if (IS_FWI2_CAPABLE(fcport->vha->hw))
  1294. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1295. fcport->loop_id, fcport->d_id.b.domain,
  1296. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1297. else
  1298. qla2x00_port_logout(fcport->vha, fcport);
  1299. }
  1300. }
  1301. static int
  1302. qla2x00_issue_lip(struct Scsi_Host *shost)
  1303. {
  1304. scsi_qla_host_t *vha = shost_priv(shost);
  1305. qla2x00_loop_reset(vha);
  1306. return 0;
  1307. }
  1308. static struct fc_host_statistics *
  1309. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1310. {
  1311. scsi_qla_host_t *vha = shost_priv(shost);
  1312. struct qla_hw_data *ha = vha->hw;
  1313. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1314. int rval;
  1315. struct link_statistics *stats;
  1316. dma_addr_t stats_dma;
  1317. struct fc_host_statistics *pfc_host_stat;
  1318. pfc_host_stat = &vha->fc_host_stat;
  1319. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1320. if (test_bit(UNLOADING, &vha->dpc_flags))
  1321. goto done;
  1322. if (unlikely(pci_channel_offline(ha->pdev)))
  1323. goto done;
  1324. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1325. if (stats == NULL) {
  1326. ql_log(ql_log_warn, vha, 0x707d,
  1327. "Failed to allocate memory for stats.\n");
  1328. goto done;
  1329. }
  1330. memset(stats, 0, DMA_POOL_SIZE);
  1331. rval = QLA_FUNCTION_FAILED;
  1332. if (IS_FWI2_CAPABLE(ha)) {
  1333. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1334. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1335. !qla2x00_reset_active(vha) && !ha->dpc_active) {
  1336. /* Must be in a 'READY' state for statistics retrieval. */
  1337. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1338. stats, stats_dma);
  1339. }
  1340. if (rval != QLA_SUCCESS)
  1341. goto done_free;
  1342. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1343. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1344. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1345. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1346. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1347. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1348. if (IS_FWI2_CAPABLE(ha)) {
  1349. pfc_host_stat->lip_count = stats->lip_cnt;
  1350. pfc_host_stat->tx_frames = stats->tx_frames;
  1351. pfc_host_stat->rx_frames = stats->rx_frames;
  1352. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1353. pfc_host_stat->nos_count = stats->nos_rcvd;
  1354. }
  1355. pfc_host_stat->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
  1356. pfc_host_stat->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
  1357. done_free:
  1358. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1359. done:
  1360. return pfc_host_stat;
  1361. }
  1362. static void
  1363. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1364. {
  1365. scsi_qla_host_t *vha = shost_priv(shost);
  1366. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1367. }
  1368. static void
  1369. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1370. {
  1371. scsi_qla_host_t *vha = shost_priv(shost);
  1372. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1373. }
  1374. static void
  1375. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1376. {
  1377. scsi_qla_host_t *vha = shost_priv(shost);
  1378. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1379. 0xFF, 0xFF, 0xFF, 0xFF};
  1380. u64 fabric_name = wwn_to_u64(node_name);
  1381. if (vha->device_flags & SWITCH_FOUND)
  1382. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1383. fc_host_fabric_name(shost) = fabric_name;
  1384. }
  1385. static void
  1386. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1387. {
  1388. scsi_qla_host_t *vha = shost_priv(shost);
  1389. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1390. if (!base_vha->flags.online) {
  1391. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1392. return;
  1393. }
  1394. switch (atomic_read(&base_vha->loop_state)) {
  1395. case LOOP_UPDATE:
  1396. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1397. break;
  1398. case LOOP_DOWN:
  1399. if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
  1400. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1401. else
  1402. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1403. break;
  1404. case LOOP_DEAD:
  1405. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1406. break;
  1407. case LOOP_READY:
  1408. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1409. break;
  1410. default:
  1411. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1412. break;
  1413. }
  1414. }
  1415. static int
  1416. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1417. {
  1418. int ret = 0;
  1419. uint8_t qos = 0;
  1420. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1421. scsi_qla_host_t *vha = NULL;
  1422. struct qla_hw_data *ha = base_vha->hw;
  1423. uint16_t options = 0;
  1424. int cnt;
  1425. struct req_que *req = ha->req_q_map[0];
  1426. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1427. if (ret) {
  1428. ql_log(ql_log_warn, vha, 0x707e,
  1429. "Vport sanity check failed, status %x\n", ret);
  1430. return (ret);
  1431. }
  1432. vha = qla24xx_create_vhost(fc_vport);
  1433. if (vha == NULL) {
  1434. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1435. return FC_VPORT_FAILED;
  1436. }
  1437. if (disable) {
  1438. atomic_set(&vha->vp_state, VP_OFFLINE);
  1439. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1440. } else
  1441. atomic_set(&vha->vp_state, VP_FAILED);
  1442. /* ready to create vport */
  1443. ql_log(ql_log_info, vha, 0x7080,
  1444. "VP entry id %d assigned.\n", vha->vp_idx);
  1445. /* initialized vport states */
  1446. atomic_set(&vha->loop_state, LOOP_DOWN);
  1447. vha->vp_err_state= VP_ERR_PORTDWN;
  1448. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1449. /* Check if physical ha port is Up */
  1450. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1451. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1452. /* Don't retry or attempt login of this virtual port */
  1453. ql_dbg(ql_dbg_user, vha, 0x7081,
  1454. "Vport loop state is not UP.\n");
  1455. atomic_set(&vha->loop_state, LOOP_DEAD);
  1456. if (!disable)
  1457. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1458. }
  1459. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  1460. if (ha->fw_attributes & BIT_4) {
  1461. int prot = 0;
  1462. vha->flags.difdix_supported = 1;
  1463. ql_dbg(ql_dbg_user, vha, 0x7082,
  1464. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1465. if (ql2xenabledif == 1)
  1466. prot = SHOST_DIX_TYPE0_PROTECTION;
  1467. scsi_host_set_prot(vha->host,
  1468. prot | SHOST_DIF_TYPE1_PROTECTION
  1469. | SHOST_DIF_TYPE2_PROTECTION
  1470. | SHOST_DIF_TYPE3_PROTECTION
  1471. | SHOST_DIX_TYPE1_PROTECTION
  1472. | SHOST_DIX_TYPE2_PROTECTION
  1473. | SHOST_DIX_TYPE3_PROTECTION);
  1474. scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
  1475. } else
  1476. vha->flags.difdix_supported = 0;
  1477. }
  1478. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1479. &ha->pdev->dev)) {
  1480. ql_dbg(ql_dbg_user, vha, 0x7083,
  1481. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1482. goto vport_create_failed_2;
  1483. }
  1484. /* initialize attributes */
  1485. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1486. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1487. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1488. fc_host_supported_classes(vha->host) =
  1489. fc_host_supported_classes(base_vha->host);
  1490. fc_host_supported_speeds(vha->host) =
  1491. fc_host_supported_speeds(base_vha->host);
  1492. qlt_vport_create(vha, ha);
  1493. qla24xx_vport_disable(fc_vport, disable);
  1494. if (ha->flags.cpu_affinity_enabled) {
  1495. req = ha->req_q_map[1];
  1496. ql_dbg(ql_dbg_multiq, vha, 0xc000,
  1497. "Request queue %p attached with "
  1498. "VP[%d], cpu affinity =%d\n",
  1499. req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
  1500. goto vport_queue;
  1501. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1502. goto vport_queue;
  1503. /* Create a request queue in QoS mode for the vport */
  1504. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1505. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1506. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1507. 8) == 0) {
  1508. qos = ha->npiv_info[cnt].q_qos;
  1509. break;
  1510. }
  1511. }
  1512. if (qos) {
  1513. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1514. qos);
  1515. if (!ret)
  1516. ql_log(ql_log_warn, vha, 0x7084,
  1517. "Can't create request queue for VP[%d]\n",
  1518. vha->vp_idx);
  1519. else {
  1520. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1521. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1522. ret, qos, vha->vp_idx);
  1523. ql_dbg(ql_dbg_user, vha, 0x7085,
  1524. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1525. ret, qos, vha->vp_idx);
  1526. req = ha->req_q_map[ret];
  1527. }
  1528. }
  1529. vport_queue:
  1530. vha->req = req;
  1531. return 0;
  1532. vport_create_failed_2:
  1533. qla24xx_disable_vp(vha);
  1534. qla24xx_deallocate_vp_id(vha);
  1535. scsi_host_put(vha->host);
  1536. return FC_VPORT_FAILED;
  1537. }
  1538. static int
  1539. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1540. {
  1541. scsi_qla_host_t *vha = fc_vport->dd_data;
  1542. struct qla_hw_data *ha = vha->hw;
  1543. uint16_t id = vha->vp_idx;
  1544. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1545. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1546. msleep(1000);
  1547. qla24xx_disable_vp(vha);
  1548. vha->flags.delete_progress = 1;
  1549. fc_remove_host(vha->host);
  1550. scsi_remove_host(vha->host);
  1551. /* Allow timer to run to drain queued items, when removing vp */
  1552. qla24xx_deallocate_vp_id(vha);
  1553. if (vha->timer_active) {
  1554. qla2x00_vp_stop_timer(vha);
  1555. ql_dbg(ql_dbg_user, vha, 0x7086,
  1556. "Timer for the VP[%d] has stopped\n", vha->vp_idx);
  1557. }
  1558. /* No pending activities shall be there on the vha now */
  1559. if (ql2xextended_error_logging & ql_dbg_user)
  1560. msleep(random32()%10); /* Just to see if something falls on
  1561. * the net we have placed below */
  1562. BUG_ON(atomic_read(&vha->vref_count));
  1563. qla2x00_free_fcports(vha);
  1564. mutex_lock(&ha->vport_lock);
  1565. ha->cur_vport_count--;
  1566. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1567. mutex_unlock(&ha->vport_lock);
  1568. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1569. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1570. ql_log(ql_log_warn, vha, 0x7087,
  1571. "Queue delete failed.\n");
  1572. }
  1573. ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
  1574. scsi_host_put(vha->host);
  1575. return 0;
  1576. }
  1577. static int
  1578. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1579. {
  1580. scsi_qla_host_t *vha = fc_vport->dd_data;
  1581. if (disable)
  1582. qla24xx_disable_vp(vha);
  1583. else
  1584. qla24xx_enable_vp(vha);
  1585. return 0;
  1586. }
  1587. struct fc_function_template qla2xxx_transport_functions = {
  1588. .show_host_node_name = 1,
  1589. .show_host_port_name = 1,
  1590. .show_host_supported_classes = 1,
  1591. .show_host_supported_speeds = 1,
  1592. .get_host_port_id = qla2x00_get_host_port_id,
  1593. .show_host_port_id = 1,
  1594. .get_host_speed = qla2x00_get_host_speed,
  1595. .show_host_speed = 1,
  1596. .get_host_port_type = qla2x00_get_host_port_type,
  1597. .show_host_port_type = 1,
  1598. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1599. .show_host_symbolic_name = 1,
  1600. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1601. .show_host_system_hostname = 1,
  1602. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1603. .show_host_fabric_name = 1,
  1604. .get_host_port_state = qla2x00_get_host_port_state,
  1605. .show_host_port_state = 1,
  1606. .dd_fcrport_size = sizeof(struct fc_port *),
  1607. .show_rport_supported_classes = 1,
  1608. .get_starget_node_name = qla2x00_get_starget_node_name,
  1609. .show_starget_node_name = 1,
  1610. .get_starget_port_name = qla2x00_get_starget_port_name,
  1611. .show_starget_port_name = 1,
  1612. .get_starget_port_id = qla2x00_get_starget_port_id,
  1613. .show_starget_port_id = 1,
  1614. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1615. .show_rport_dev_loss_tmo = 1,
  1616. .issue_fc_host_lip = qla2x00_issue_lip,
  1617. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1618. .terminate_rport_io = qla2x00_terminate_rport_io,
  1619. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1620. .vport_create = qla24xx_vport_create,
  1621. .vport_disable = qla24xx_vport_disable,
  1622. .vport_delete = qla24xx_vport_delete,
  1623. .bsg_request = qla24xx_bsg_request,
  1624. .bsg_timeout = qla24xx_bsg_timeout,
  1625. };
  1626. struct fc_function_template qla2xxx_transport_vport_functions = {
  1627. .show_host_node_name = 1,
  1628. .show_host_port_name = 1,
  1629. .show_host_supported_classes = 1,
  1630. .get_host_port_id = qla2x00_get_host_port_id,
  1631. .show_host_port_id = 1,
  1632. .get_host_speed = qla2x00_get_host_speed,
  1633. .show_host_speed = 1,
  1634. .get_host_port_type = qla2x00_get_host_port_type,
  1635. .show_host_port_type = 1,
  1636. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1637. .show_host_symbolic_name = 1,
  1638. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1639. .show_host_system_hostname = 1,
  1640. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1641. .show_host_fabric_name = 1,
  1642. .get_host_port_state = qla2x00_get_host_port_state,
  1643. .show_host_port_state = 1,
  1644. .dd_fcrport_size = sizeof(struct fc_port *),
  1645. .show_rport_supported_classes = 1,
  1646. .get_starget_node_name = qla2x00_get_starget_node_name,
  1647. .show_starget_node_name = 1,
  1648. .get_starget_port_name = qla2x00_get_starget_port_name,
  1649. .show_starget_port_name = 1,
  1650. .get_starget_port_id = qla2x00_get_starget_port_id,
  1651. .show_starget_port_id = 1,
  1652. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1653. .show_rport_dev_loss_tmo = 1,
  1654. .issue_fc_host_lip = qla2x00_issue_lip,
  1655. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1656. .terminate_rport_io = qla2x00_terminate_rport_io,
  1657. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1658. .bsg_request = qla24xx_bsg_request,
  1659. .bsg_timeout = qla24xx_bsg_timeout,
  1660. };
  1661. void
  1662. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1663. {
  1664. struct qla_hw_data *ha = vha->hw;
  1665. u32 speed = FC_PORTSPEED_UNKNOWN;
  1666. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1667. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1668. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1669. fc_host_supported_classes(vha->host) = ha->tgt.enable_class_2 ?
  1670. (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
  1671. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1672. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1673. if (IS_CNA_CAPABLE(ha))
  1674. speed = FC_PORTSPEED_10GBIT;
  1675. else if (IS_QLA2031(ha))
  1676. speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
  1677. FC_PORTSPEED_4GBIT;
  1678. else if (IS_QLA25XX(ha))
  1679. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1680. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1681. else if (IS_QLA24XX_TYPE(ha))
  1682. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1683. FC_PORTSPEED_1GBIT;
  1684. else if (IS_QLA23XX(ha))
  1685. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1686. else
  1687. speed = FC_PORTSPEED_1GBIT;
  1688. fc_host_supported_speeds(vha->host) = speed;
  1689. }