qla_attr.c 52 KB

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