qla_attr.c 49 KB

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