qla_attr.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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. /* Read NVRAM data from cache. */
  84. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  85. ha->nvram_size);
  86. }
  87. static ssize_t
  88. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  89. struct bin_attribute *bin_attr,
  90. char *buf, loff_t off, size_t count)
  91. {
  92. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  93. struct device, kobj)));
  94. struct qla_hw_data *ha = vha->hw;
  95. uint16_t cnt;
  96. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
  97. return 0;
  98. /* Checksum NVRAM. */
  99. if (IS_FWI2_CAPABLE(ha)) {
  100. uint32_t *iter;
  101. uint32_t chksum;
  102. iter = (uint32_t *)buf;
  103. chksum = 0;
  104. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  105. chksum += le32_to_cpu(*iter++);
  106. chksum = ~chksum + 1;
  107. *iter = cpu_to_le32(chksum);
  108. } else {
  109. uint8_t *iter;
  110. uint8_t chksum;
  111. iter = (uint8_t *)buf;
  112. chksum = 0;
  113. for (cnt = 0; cnt < count - 1; cnt++)
  114. chksum += *iter++;
  115. chksum = ~chksum + 1;
  116. *iter = chksum;
  117. }
  118. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  119. qla_printk(KERN_WARNING, ha,
  120. "HBA not online, failing NVRAM update.\n");
  121. return -EAGAIN;
  122. }
  123. /* Write NVRAM. */
  124. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  125. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  126. count);
  127. /* NVRAM settings take effect immediately. */
  128. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  129. qla2xxx_wake_dpc(vha);
  130. qla2x00_wait_for_chip_reset(vha);
  131. return (count);
  132. }
  133. static struct bin_attribute sysfs_nvram_attr = {
  134. .attr = {
  135. .name = "nvram",
  136. .mode = S_IRUSR | S_IWUSR,
  137. },
  138. .size = 512,
  139. .read = qla2x00_sysfs_read_nvram,
  140. .write = qla2x00_sysfs_write_nvram,
  141. };
  142. static ssize_t
  143. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  144. struct bin_attribute *bin_attr,
  145. char *buf, loff_t off, size_t count)
  146. {
  147. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  148. struct device, kobj)));
  149. struct qla_hw_data *ha = vha->hw;
  150. if (ha->optrom_state != QLA_SREADING)
  151. return 0;
  152. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  153. ha->optrom_region_size);
  154. }
  155. static ssize_t
  156. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  157. struct bin_attribute *bin_attr,
  158. char *buf, loff_t off, size_t count)
  159. {
  160. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  161. struct device, kobj)));
  162. struct qla_hw_data *ha = vha->hw;
  163. if (ha->optrom_state != QLA_SWRITING)
  164. return -EINVAL;
  165. if (off > ha->optrom_region_size)
  166. return -ERANGE;
  167. if (off + count > ha->optrom_region_size)
  168. count = ha->optrom_region_size - off;
  169. memcpy(&ha->optrom_buffer[off], buf, count);
  170. return count;
  171. }
  172. static struct bin_attribute sysfs_optrom_attr = {
  173. .attr = {
  174. .name = "optrom",
  175. .mode = S_IRUSR | S_IWUSR,
  176. },
  177. .size = 0,
  178. .read = qla2x00_sysfs_read_optrom,
  179. .write = qla2x00_sysfs_write_optrom,
  180. };
  181. static ssize_t
  182. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  183. struct bin_attribute *bin_attr,
  184. char *buf, loff_t off, size_t count)
  185. {
  186. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  187. struct device, kobj)));
  188. struct qla_hw_data *ha = vha->hw;
  189. uint32_t start = 0;
  190. uint32_t size = ha->optrom_size;
  191. int val, valid;
  192. if (off)
  193. return 0;
  194. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  195. return -EINVAL;
  196. if (start > ha->optrom_size)
  197. return -EINVAL;
  198. switch (val) {
  199. case 0:
  200. if (ha->optrom_state != QLA_SREADING &&
  201. ha->optrom_state != QLA_SWRITING)
  202. break;
  203. ha->optrom_state = QLA_SWAITING;
  204. DEBUG2(qla_printk(KERN_INFO, ha,
  205. "Freeing flash region allocation -- 0x%x bytes.\n",
  206. ha->optrom_region_size));
  207. vfree(ha->optrom_buffer);
  208. ha->optrom_buffer = NULL;
  209. break;
  210. case 1:
  211. if (ha->optrom_state != QLA_SWAITING)
  212. break;
  213. ha->optrom_region_start = start;
  214. ha->optrom_region_size = start + size > ha->optrom_size ?
  215. ha->optrom_size - start : size;
  216. ha->optrom_state = QLA_SREADING;
  217. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  218. if (ha->optrom_buffer == NULL) {
  219. qla_printk(KERN_WARNING, ha,
  220. "Unable to allocate memory for optrom retrieval "
  221. "(%x).\n", ha->optrom_region_size);
  222. ha->optrom_state = QLA_SWAITING;
  223. return count;
  224. }
  225. DEBUG2(qla_printk(KERN_INFO, ha,
  226. "Reading flash region -- 0x%x/0x%x.\n",
  227. ha->optrom_region_start, ha->optrom_region_size));
  228. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  229. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  230. ha->optrom_region_start, ha->optrom_region_size);
  231. break;
  232. case 2:
  233. if (ha->optrom_state != QLA_SWAITING)
  234. break;
  235. /*
  236. * We need to be more restrictive on which FLASH regions are
  237. * allowed to be updated via user-space. Regions accessible
  238. * via this method include:
  239. *
  240. * ISP21xx/ISP22xx/ISP23xx type boards:
  241. *
  242. * 0x000000 -> 0x020000 -- Boot code.
  243. *
  244. * ISP2322/ISP24xx type boards:
  245. *
  246. * 0x000000 -> 0x07ffff -- Boot code.
  247. * 0x080000 -> 0x0fffff -- Firmware.
  248. *
  249. * ISP25xx type boards:
  250. *
  251. * 0x000000 -> 0x07ffff -- Boot code.
  252. * 0x080000 -> 0x0fffff -- Firmware.
  253. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  254. */
  255. valid = 0;
  256. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  257. valid = 1;
  258. else if (start == (ha->flt_region_boot * 4) ||
  259. start == (ha->flt_region_fw * 4))
  260. valid = 1;
  261. else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
  262. valid = 1;
  263. if (!valid) {
  264. qla_printk(KERN_WARNING, ha,
  265. "Invalid start region 0x%x/0x%x.\n", start, size);
  266. return -EINVAL;
  267. }
  268. ha->optrom_region_start = start;
  269. ha->optrom_region_size = start + size > ha->optrom_size ?
  270. ha->optrom_size - start : size;
  271. ha->optrom_state = QLA_SWRITING;
  272. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  273. if (ha->optrom_buffer == NULL) {
  274. qla_printk(KERN_WARNING, ha,
  275. "Unable to allocate memory for optrom update "
  276. "(%x).\n", ha->optrom_region_size);
  277. ha->optrom_state = QLA_SWAITING;
  278. return count;
  279. }
  280. DEBUG2(qla_printk(KERN_INFO, ha,
  281. "Staging flash region write -- 0x%x/0x%x.\n",
  282. ha->optrom_region_start, ha->optrom_region_size));
  283. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  284. break;
  285. case 3:
  286. if (ha->optrom_state != QLA_SWRITING)
  287. break;
  288. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  289. qla_printk(KERN_WARNING, ha,
  290. "HBA not online, failing flash update.\n");
  291. return -EAGAIN;
  292. }
  293. DEBUG2(qla_printk(KERN_INFO, ha,
  294. "Writing flash region -- 0x%x/0x%x.\n",
  295. ha->optrom_region_start, ha->optrom_region_size));
  296. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  297. ha->optrom_region_start, ha->optrom_region_size);
  298. break;
  299. default:
  300. count = -EINVAL;
  301. }
  302. return count;
  303. }
  304. static struct bin_attribute sysfs_optrom_ctl_attr = {
  305. .attr = {
  306. .name = "optrom_ctl",
  307. .mode = S_IWUSR,
  308. },
  309. .size = 0,
  310. .write = qla2x00_sysfs_write_optrom_ctl,
  311. };
  312. static ssize_t
  313. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  314. struct bin_attribute *bin_attr,
  315. char *buf, loff_t off, size_t count)
  316. {
  317. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  318. struct device, kobj)));
  319. struct qla_hw_data *ha = vha->hw;
  320. if (!capable(CAP_SYS_ADMIN))
  321. return 0;
  322. /* Read NVRAM data from cache. */
  323. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  324. }
  325. static ssize_t
  326. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  327. struct bin_attribute *bin_attr,
  328. char *buf, loff_t off, size_t count)
  329. {
  330. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  331. struct device, kobj)));
  332. struct qla_hw_data *ha = vha->hw;
  333. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
  334. return 0;
  335. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  336. qla_printk(KERN_WARNING, ha,
  337. "HBA not online, failing VPD update.\n");
  338. return -EAGAIN;
  339. }
  340. /* Write NVRAM. */
  341. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  342. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  343. return count;
  344. }
  345. static struct bin_attribute sysfs_vpd_attr = {
  346. .attr = {
  347. .name = "vpd",
  348. .mode = S_IRUSR | S_IWUSR,
  349. },
  350. .size = 0,
  351. .read = qla2x00_sysfs_read_vpd,
  352. .write = qla2x00_sysfs_write_vpd,
  353. };
  354. static ssize_t
  355. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  356. struct bin_attribute *bin_attr,
  357. char *buf, loff_t off, size_t count)
  358. {
  359. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  360. struct device, kobj)));
  361. struct qla_hw_data *ha = vha->hw;
  362. uint16_t iter, addr, offset;
  363. int rval;
  364. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  365. return 0;
  366. if (ha->sfp_data)
  367. goto do_read;
  368. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  369. &ha->sfp_data_dma);
  370. if (!ha->sfp_data) {
  371. qla_printk(KERN_WARNING, ha,
  372. "Unable to allocate memory for SFP read-data.\n");
  373. return 0;
  374. }
  375. do_read:
  376. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  377. addr = 0xa0;
  378. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  379. iter++, offset += SFP_BLOCK_SIZE) {
  380. if (iter == 4) {
  381. /* Skip to next device address. */
  382. addr = 0xa2;
  383. offset = 0;
  384. }
  385. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  386. SFP_BLOCK_SIZE);
  387. if (rval != QLA_SUCCESS) {
  388. qla_printk(KERN_WARNING, ha,
  389. "Unable to read SFP data (%x/%x/%x).\n", rval,
  390. addr, offset);
  391. count = 0;
  392. break;
  393. }
  394. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  395. buf += SFP_BLOCK_SIZE;
  396. }
  397. return count;
  398. }
  399. static struct bin_attribute sysfs_sfp_attr = {
  400. .attr = {
  401. .name = "sfp",
  402. .mode = S_IRUSR | S_IWUSR,
  403. },
  404. .size = SFP_DEV_SIZE * 2,
  405. .read = qla2x00_sysfs_read_sfp,
  406. };
  407. static ssize_t
  408. qla2x00_sysfs_write_reset(struct kobject *kobj,
  409. struct bin_attribute *bin_attr,
  410. char *buf, loff_t off, size_t count)
  411. {
  412. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  413. struct device, kobj)));
  414. struct qla_hw_data *ha = vha->hw;
  415. int type;
  416. if (off != 0)
  417. return 0;
  418. type = simple_strtol(buf, NULL, 10);
  419. switch (type) {
  420. case 0x2025c:
  421. qla_printk(KERN_INFO, ha,
  422. "Issuing ISP reset on (%ld).\n", vha->host_no);
  423. scsi_block_requests(vha->host);
  424. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  425. qla2xxx_wake_dpc(vha);
  426. qla2x00_wait_for_chip_reset(vha);
  427. scsi_unblock_requests(vha->host);
  428. break;
  429. case 0x2025d:
  430. if (!IS_QLA81XX(ha))
  431. break;
  432. qla_printk(KERN_INFO, ha,
  433. "Issuing MPI reset on (%ld).\n", vha->host_no);
  434. /* Make sure FC side is not in reset */
  435. qla2x00_wait_for_hba_online(vha);
  436. /* Issue MPI reset */
  437. scsi_block_requests(vha->host);
  438. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  439. qla_printk(KERN_WARNING, ha,
  440. "MPI reset failed on (%ld).\n", vha->host_no);
  441. scsi_unblock_requests(vha->host);
  442. break;
  443. }
  444. return count;
  445. }
  446. static struct bin_attribute sysfs_reset_attr = {
  447. .attr = {
  448. .name = "reset",
  449. .mode = S_IWUSR,
  450. },
  451. .size = 0,
  452. .write = qla2x00_sysfs_write_reset,
  453. };
  454. static struct sysfs_entry {
  455. char *name;
  456. struct bin_attribute *attr;
  457. int is4GBp_only;
  458. } bin_file_entries[] = {
  459. { "fw_dump", &sysfs_fw_dump_attr, },
  460. { "nvram", &sysfs_nvram_attr, },
  461. { "optrom", &sysfs_optrom_attr, },
  462. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  463. { "vpd", &sysfs_vpd_attr, 1 },
  464. { "sfp", &sysfs_sfp_attr, 1 },
  465. { "reset", &sysfs_reset_attr, },
  466. { NULL },
  467. };
  468. void
  469. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  470. {
  471. struct Scsi_Host *host = vha->host;
  472. struct sysfs_entry *iter;
  473. int ret;
  474. for (iter = bin_file_entries; iter->name; iter++) {
  475. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  476. continue;
  477. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  478. iter->attr);
  479. if (ret)
  480. qla_printk(KERN_INFO, vha->hw,
  481. "Unable to create sysfs %s binary attribute "
  482. "(%d).\n", iter->name, ret);
  483. }
  484. }
  485. void
  486. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  487. {
  488. struct Scsi_Host *host = vha->host;
  489. struct sysfs_entry *iter;
  490. struct qla_hw_data *ha = vha->hw;
  491. for (iter = bin_file_entries; iter->name; iter++) {
  492. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  493. continue;
  494. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  495. iter->attr);
  496. }
  497. if (ha->beacon_blink_led == 1)
  498. ha->isp_ops->beacon_off(vha);
  499. }
  500. /* Scsi_Host attributes. */
  501. static ssize_t
  502. qla2x00_drvr_version_show(struct device *dev,
  503. struct device_attribute *attr, char *buf)
  504. {
  505. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  506. }
  507. static ssize_t
  508. qla2x00_fw_version_show(struct device *dev,
  509. struct device_attribute *attr, char *buf)
  510. {
  511. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  512. struct qla_hw_data *ha = vha->hw;
  513. char fw_str[128];
  514. return snprintf(buf, PAGE_SIZE, "%s\n",
  515. ha->isp_ops->fw_version_str(vha, fw_str));
  516. }
  517. static ssize_t
  518. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  519. char *buf)
  520. {
  521. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  522. struct qla_hw_data *ha = vha->hw;
  523. uint32_t sn;
  524. if (IS_FWI2_CAPABLE(ha)) {
  525. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  526. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  527. }
  528. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  529. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  530. sn % 100000);
  531. }
  532. static ssize_t
  533. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  534. char *buf)
  535. {
  536. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  537. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  538. }
  539. static ssize_t
  540. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  541. char *buf)
  542. {
  543. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  544. struct qla_hw_data *ha = vha->hw;
  545. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  546. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  547. ha->product_id[3]);
  548. }
  549. static ssize_t
  550. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  551. char *buf)
  552. {
  553. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  554. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  555. }
  556. static ssize_t
  557. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  558. char *buf)
  559. {
  560. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  561. return snprintf(buf, PAGE_SIZE, "%s\n",
  562. vha->hw->model_desc ? vha->hw->model_desc : "");
  563. }
  564. static ssize_t
  565. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  566. char *buf)
  567. {
  568. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  569. char pci_info[30];
  570. return snprintf(buf, PAGE_SIZE, "%s\n",
  571. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  572. }
  573. static ssize_t
  574. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  575. char *buf)
  576. {
  577. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  578. struct qla_hw_data *ha = vha->hw;
  579. int len = 0;
  580. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  581. atomic_read(&vha->loop_state) == LOOP_DEAD)
  582. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  583. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  584. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  585. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  586. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  587. else {
  588. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  589. switch (ha->current_topology) {
  590. case ISP_CFG_NL:
  591. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  592. break;
  593. case ISP_CFG_FL:
  594. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  595. break;
  596. case ISP_CFG_N:
  597. len += snprintf(buf + len, PAGE_SIZE-len,
  598. "N_Port to N_Port\n");
  599. break;
  600. case ISP_CFG_F:
  601. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  602. break;
  603. default:
  604. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  605. break;
  606. }
  607. }
  608. return len;
  609. }
  610. static ssize_t
  611. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  612. char *buf)
  613. {
  614. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  615. int len = 0;
  616. switch (vha->hw->zio_mode) {
  617. case QLA_ZIO_MODE_6:
  618. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  619. break;
  620. case QLA_ZIO_DISABLED:
  621. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  622. break;
  623. }
  624. return len;
  625. }
  626. static ssize_t
  627. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  628. const char *buf, size_t count)
  629. {
  630. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  631. struct qla_hw_data *ha = vha->hw;
  632. int val = 0;
  633. uint16_t zio_mode;
  634. if (!IS_ZIO_SUPPORTED(ha))
  635. return -ENOTSUPP;
  636. if (sscanf(buf, "%d", &val) != 1)
  637. return -EINVAL;
  638. if (val)
  639. zio_mode = QLA_ZIO_MODE_6;
  640. else
  641. zio_mode = QLA_ZIO_DISABLED;
  642. /* Update per-hba values and queue a reset. */
  643. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  644. ha->zio_mode = zio_mode;
  645. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  646. }
  647. return strlen(buf);
  648. }
  649. static ssize_t
  650. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  651. char *buf)
  652. {
  653. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  654. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  655. }
  656. static ssize_t
  657. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  658. const char *buf, size_t count)
  659. {
  660. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  661. int val = 0;
  662. uint16_t zio_timer;
  663. if (sscanf(buf, "%d", &val) != 1)
  664. return -EINVAL;
  665. if (val > 25500 || val < 100)
  666. return -ERANGE;
  667. zio_timer = (uint16_t)(val / 100);
  668. vha->hw->zio_timer = zio_timer;
  669. return strlen(buf);
  670. }
  671. static ssize_t
  672. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  673. char *buf)
  674. {
  675. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  676. int len = 0;
  677. if (vha->hw->beacon_blink_led)
  678. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  679. else
  680. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  681. return len;
  682. }
  683. static ssize_t
  684. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  685. const char *buf, size_t count)
  686. {
  687. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  688. struct qla_hw_data *ha = vha->hw;
  689. int val = 0;
  690. int rval;
  691. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  692. return -EPERM;
  693. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  694. qla_printk(KERN_WARNING, ha,
  695. "Abort ISP active -- ignoring beacon request.\n");
  696. return -EBUSY;
  697. }
  698. if (sscanf(buf, "%d", &val) != 1)
  699. return -EINVAL;
  700. if (val)
  701. rval = ha->isp_ops->beacon_on(vha);
  702. else
  703. rval = ha->isp_ops->beacon_off(vha);
  704. if (rval != QLA_SUCCESS)
  705. count = 0;
  706. return count;
  707. }
  708. static ssize_t
  709. qla2x00_optrom_bios_version_show(struct device *dev,
  710. struct device_attribute *attr, char *buf)
  711. {
  712. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  713. struct qla_hw_data *ha = vha->hw;
  714. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  715. ha->bios_revision[0]);
  716. }
  717. static ssize_t
  718. qla2x00_optrom_efi_version_show(struct device *dev,
  719. struct device_attribute *attr, char *buf)
  720. {
  721. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  722. struct qla_hw_data *ha = vha->hw;
  723. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  724. ha->efi_revision[0]);
  725. }
  726. static ssize_t
  727. qla2x00_optrom_fcode_version_show(struct device *dev,
  728. struct device_attribute *attr, char *buf)
  729. {
  730. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  731. struct qla_hw_data *ha = vha->hw;
  732. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  733. ha->fcode_revision[0]);
  734. }
  735. static ssize_t
  736. qla2x00_optrom_fw_version_show(struct device *dev,
  737. struct device_attribute *attr, char *buf)
  738. {
  739. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  740. struct qla_hw_data *ha = vha->hw;
  741. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  742. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  743. ha->fw_revision[3]);
  744. }
  745. static ssize_t
  746. qla2x00_total_isp_aborts_show(struct device *dev,
  747. struct device_attribute *attr, char *buf)
  748. {
  749. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  750. struct qla_hw_data *ha = vha->hw;
  751. return snprintf(buf, PAGE_SIZE, "%d\n",
  752. ha->qla_stats.total_isp_aborts);
  753. }
  754. static ssize_t
  755. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  756. char *buf)
  757. {
  758. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  759. struct qla_hw_data *ha = vha->hw;
  760. if (!IS_QLA81XX(ha))
  761. return snprintf(buf, PAGE_SIZE, "\n");
  762. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  763. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  764. ha->mpi_capabilities);
  765. }
  766. static ssize_t
  767. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  768. char *buf)
  769. {
  770. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  771. struct qla_hw_data *ha = vha->hw;
  772. if (!IS_QLA81XX(ha))
  773. return snprintf(buf, PAGE_SIZE, "\n");
  774. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  775. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  776. }
  777. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  778. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  779. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  780. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  781. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  782. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  783. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  784. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  785. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  786. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  787. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  788. qla2x00_zio_timer_store);
  789. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  790. qla2x00_beacon_store);
  791. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  792. qla2x00_optrom_bios_version_show, NULL);
  793. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  794. qla2x00_optrom_efi_version_show, NULL);
  795. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  796. qla2x00_optrom_fcode_version_show, NULL);
  797. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  798. NULL);
  799. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  800. NULL);
  801. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  802. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  803. struct device_attribute *qla2x00_host_attrs[] = {
  804. &dev_attr_driver_version,
  805. &dev_attr_fw_version,
  806. &dev_attr_serial_num,
  807. &dev_attr_isp_name,
  808. &dev_attr_isp_id,
  809. &dev_attr_model_name,
  810. &dev_attr_model_desc,
  811. &dev_attr_pci_info,
  812. &dev_attr_link_state,
  813. &dev_attr_zio,
  814. &dev_attr_zio_timer,
  815. &dev_attr_beacon,
  816. &dev_attr_optrom_bios_version,
  817. &dev_attr_optrom_efi_version,
  818. &dev_attr_optrom_fcode_version,
  819. &dev_attr_optrom_fw_version,
  820. &dev_attr_total_isp_aborts,
  821. &dev_attr_mpi_version,
  822. &dev_attr_phy_version,
  823. NULL,
  824. };
  825. /* Host attributes. */
  826. static void
  827. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  828. {
  829. scsi_qla_host_t *vha = shost_priv(shost);
  830. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  831. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  832. }
  833. static void
  834. qla2x00_get_host_speed(struct Scsi_Host *shost)
  835. {
  836. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  837. (shost_priv(shost)))->hw;
  838. u32 speed = FC_PORTSPEED_UNKNOWN;
  839. switch (ha->link_data_rate) {
  840. case PORT_SPEED_1GB:
  841. speed = FC_PORTSPEED_1GBIT;
  842. break;
  843. case PORT_SPEED_2GB:
  844. speed = FC_PORTSPEED_2GBIT;
  845. break;
  846. case PORT_SPEED_4GB:
  847. speed = FC_PORTSPEED_4GBIT;
  848. break;
  849. case PORT_SPEED_8GB:
  850. speed = FC_PORTSPEED_8GBIT;
  851. break;
  852. case PORT_SPEED_10GB:
  853. speed = FC_PORTSPEED_10GBIT;
  854. break;
  855. }
  856. fc_host_speed(shost) = speed;
  857. }
  858. static void
  859. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  860. {
  861. scsi_qla_host_t *vha = shost_priv(shost);
  862. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  863. if (vha->vp_idx) {
  864. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  865. return;
  866. }
  867. switch (vha->hw->current_topology) {
  868. case ISP_CFG_NL:
  869. port_type = FC_PORTTYPE_LPORT;
  870. break;
  871. case ISP_CFG_FL:
  872. port_type = FC_PORTTYPE_NLPORT;
  873. break;
  874. case ISP_CFG_N:
  875. port_type = FC_PORTTYPE_PTP;
  876. break;
  877. case ISP_CFG_F:
  878. port_type = FC_PORTTYPE_NPORT;
  879. break;
  880. }
  881. fc_host_port_type(shost) = port_type;
  882. }
  883. static void
  884. qla2x00_get_starget_node_name(struct scsi_target *starget)
  885. {
  886. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  887. scsi_qla_host_t *vha = shost_priv(host);
  888. fc_port_t *fcport;
  889. u64 node_name = 0;
  890. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  891. if (fcport->rport &&
  892. starget->id == fcport->rport->scsi_target_id) {
  893. node_name = wwn_to_u64(fcport->node_name);
  894. break;
  895. }
  896. }
  897. fc_starget_node_name(starget) = node_name;
  898. }
  899. static void
  900. qla2x00_get_starget_port_name(struct scsi_target *starget)
  901. {
  902. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  903. scsi_qla_host_t *vha = shost_priv(host);
  904. fc_port_t *fcport;
  905. u64 port_name = 0;
  906. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  907. if (fcport->rport &&
  908. starget->id == fcport->rport->scsi_target_id) {
  909. port_name = wwn_to_u64(fcport->port_name);
  910. break;
  911. }
  912. }
  913. fc_starget_port_name(starget) = port_name;
  914. }
  915. static void
  916. qla2x00_get_starget_port_id(struct scsi_target *starget)
  917. {
  918. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  919. scsi_qla_host_t *vha = shost_priv(host);
  920. fc_port_t *fcport;
  921. uint32_t port_id = ~0U;
  922. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  923. if (fcport->rport &&
  924. starget->id == fcport->rport->scsi_target_id) {
  925. port_id = fcport->d_id.b.domain << 16 |
  926. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  927. break;
  928. }
  929. }
  930. fc_starget_port_id(starget) = port_id;
  931. }
  932. static void
  933. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  934. {
  935. if (timeout)
  936. rport->dev_loss_tmo = timeout;
  937. else
  938. rport->dev_loss_tmo = 1;
  939. }
  940. static void
  941. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  942. {
  943. struct Scsi_Host *host = rport_to_shost(rport);
  944. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  945. if (!fcport)
  946. return;
  947. qla2x00_abort_fcport_cmds(fcport);
  948. /*
  949. * Transport has effectively 'deleted' the rport, clear
  950. * all local references.
  951. */
  952. spin_lock_irq(host->host_lock);
  953. fcport->rport = NULL;
  954. *((fc_port_t **)rport->dd_data) = NULL;
  955. spin_unlock_irq(host->host_lock);
  956. }
  957. static void
  958. qla2x00_terminate_rport_io(struct fc_rport *rport)
  959. {
  960. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  961. if (!fcport)
  962. return;
  963. /*
  964. * At this point all fcport's software-states are cleared. Perform any
  965. * final cleanup of firmware resources (PCBs and XCBs).
  966. */
  967. if (fcport->loop_id != FC_NO_LOOP_ID)
  968. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  969. fcport->loop_id, fcport->d_id.b.domain,
  970. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  971. qla2x00_abort_fcport_cmds(fcport);
  972. }
  973. static int
  974. qla2x00_issue_lip(struct Scsi_Host *shost)
  975. {
  976. scsi_qla_host_t *vha = shost_priv(shost);
  977. qla2x00_loop_reset(vha);
  978. return 0;
  979. }
  980. static struct fc_host_statistics *
  981. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  982. {
  983. scsi_qla_host_t *vha = shost_priv(shost);
  984. struct qla_hw_data *ha = vha->hw;
  985. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  986. int rval;
  987. struct link_statistics *stats;
  988. dma_addr_t stats_dma;
  989. struct fc_host_statistics *pfc_host_stat;
  990. pfc_host_stat = &ha->fc_host_stat;
  991. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  992. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  993. if (stats == NULL) {
  994. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  995. __func__, base_vha->host_no));
  996. goto done;
  997. }
  998. memset(stats, 0, DMA_POOL_SIZE);
  999. rval = QLA_FUNCTION_FAILED;
  1000. if (IS_FWI2_CAPABLE(ha)) {
  1001. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1002. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1003. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1004. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1005. !ha->dpc_active) {
  1006. /* Must be in a 'READY' state for statistics retrieval. */
  1007. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1008. stats, stats_dma);
  1009. }
  1010. if (rval != QLA_SUCCESS)
  1011. goto done_free;
  1012. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1013. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1014. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1015. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1016. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1017. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1018. if (IS_FWI2_CAPABLE(ha)) {
  1019. pfc_host_stat->lip_count = stats->lip_cnt;
  1020. pfc_host_stat->tx_frames = stats->tx_frames;
  1021. pfc_host_stat->rx_frames = stats->rx_frames;
  1022. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1023. pfc_host_stat->nos_count = stats->nos_rcvd;
  1024. }
  1025. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1026. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1027. done_free:
  1028. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1029. done:
  1030. return pfc_host_stat;
  1031. }
  1032. static void
  1033. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1034. {
  1035. scsi_qla_host_t *vha = shost_priv(shost);
  1036. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1037. }
  1038. static void
  1039. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1040. {
  1041. scsi_qla_host_t *vha = shost_priv(shost);
  1042. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1043. }
  1044. static void
  1045. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1046. {
  1047. scsi_qla_host_t *vha = shost_priv(shost);
  1048. u64 node_name;
  1049. if (vha->device_flags & SWITCH_FOUND)
  1050. node_name = wwn_to_u64(vha->fabric_node_name);
  1051. else
  1052. node_name = wwn_to_u64(vha->node_name);
  1053. fc_host_fabric_name(shost) = node_name;
  1054. }
  1055. static void
  1056. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1057. {
  1058. scsi_qla_host_t *vha = shost_priv(shost);
  1059. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1060. if (!base_vha->flags.online)
  1061. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1062. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1063. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1064. else
  1065. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1066. }
  1067. static int
  1068. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1069. {
  1070. int ret = 0;
  1071. int cnt = 0;
  1072. uint8_t qos = QLA_DEFAULT_QUE_QOS;
  1073. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1074. scsi_qla_host_t *vha = NULL;
  1075. struct qla_hw_data *ha = base_vha->hw;
  1076. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1077. if (ret) {
  1078. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1079. "status %x\n", ret));
  1080. return (ret);
  1081. }
  1082. vha = qla24xx_create_vhost(fc_vport);
  1083. if (vha == NULL) {
  1084. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1085. vha));
  1086. return FC_VPORT_FAILED;
  1087. }
  1088. if (disable) {
  1089. atomic_set(&vha->vp_state, VP_OFFLINE);
  1090. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1091. } else
  1092. atomic_set(&vha->vp_state, VP_FAILED);
  1093. /* ready to create vport */
  1094. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1095. vha->vp_idx);
  1096. /* initialized vport states */
  1097. atomic_set(&vha->loop_state, LOOP_DOWN);
  1098. vha->vp_err_state= VP_ERR_PORTDWN;
  1099. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1100. /* Check if physical ha port is Up */
  1101. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1102. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1103. /* Don't retry or attempt login of this virtual port */
  1104. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1105. base_vha->host_no));
  1106. atomic_set(&vha->loop_state, LOOP_DEAD);
  1107. if (!disable)
  1108. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1109. }
  1110. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  1111. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1112. vha->host_no, vha->vp_idx));
  1113. goto vport_create_failed_2;
  1114. }
  1115. /* initialize attributes */
  1116. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1117. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1118. fc_host_supported_classes(vha->host) =
  1119. fc_host_supported_classes(base_vha->host);
  1120. fc_host_supported_speeds(vha->host) =
  1121. fc_host_supported_speeds(base_vha->host);
  1122. qla24xx_vport_disable(fc_vport, disable);
  1123. /* Create a queue pair for the vport */
  1124. if (ha->mqenable) {
  1125. if (ha->npiv_info) {
  1126. for (; cnt < ha->nvram_npiv_size; cnt++) {
  1127. if (ha->npiv_info[cnt].port_name ==
  1128. vha->port_name &&
  1129. ha->npiv_info[cnt].node_name ==
  1130. vha->node_name) {
  1131. qos = ha->npiv_info[cnt].q_qos;
  1132. break;
  1133. }
  1134. }
  1135. }
  1136. qla25xx_create_queues(vha, qos);
  1137. }
  1138. return 0;
  1139. vport_create_failed_2:
  1140. qla24xx_disable_vp(vha);
  1141. qla24xx_deallocate_vp_id(vha);
  1142. scsi_host_put(vha->host);
  1143. return FC_VPORT_FAILED;
  1144. }
  1145. static int
  1146. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1147. {
  1148. scsi_qla_host_t *vha = fc_vport->dd_data;
  1149. fc_port_t *fcport, *tfcport;
  1150. struct qla_hw_data *ha = vha->hw;
  1151. uint16_t id = vha->vp_idx;
  1152. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1153. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1154. msleep(1000);
  1155. qla24xx_disable_vp(vha);
  1156. fc_remove_host(vha->host);
  1157. scsi_remove_host(vha->host);
  1158. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1159. list_del(&fcport->list);
  1160. kfree(fcport);
  1161. fcport = NULL;
  1162. }
  1163. qla24xx_deallocate_vp_id(vha);
  1164. if (vha->timer_active) {
  1165. qla2x00_vp_stop_timer(vha);
  1166. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1167. "has stopped\n",
  1168. vha->host_no, vha->vp_idx, vha));
  1169. }
  1170. if (ha->mqenable) {
  1171. if (qla25xx_delete_queues(vha, 0) != QLA_SUCCESS)
  1172. qla_printk(KERN_WARNING, ha,
  1173. "Queue delete failed.\n");
  1174. }
  1175. scsi_host_put(vha->host);
  1176. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1177. return 0;
  1178. }
  1179. static int
  1180. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1181. {
  1182. scsi_qla_host_t *vha = fc_vport->dd_data;
  1183. if (disable)
  1184. qla24xx_disable_vp(vha);
  1185. else
  1186. qla24xx_enable_vp(vha);
  1187. return 0;
  1188. }
  1189. struct fc_function_template qla2xxx_transport_functions = {
  1190. .show_host_node_name = 1,
  1191. .show_host_port_name = 1,
  1192. .show_host_supported_classes = 1,
  1193. .show_host_supported_speeds = 1,
  1194. .get_host_port_id = qla2x00_get_host_port_id,
  1195. .show_host_port_id = 1,
  1196. .get_host_speed = qla2x00_get_host_speed,
  1197. .show_host_speed = 1,
  1198. .get_host_port_type = qla2x00_get_host_port_type,
  1199. .show_host_port_type = 1,
  1200. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1201. .show_host_symbolic_name = 1,
  1202. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1203. .show_host_system_hostname = 1,
  1204. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1205. .show_host_fabric_name = 1,
  1206. .get_host_port_state = qla2x00_get_host_port_state,
  1207. .show_host_port_state = 1,
  1208. .dd_fcrport_size = sizeof(struct fc_port *),
  1209. .show_rport_supported_classes = 1,
  1210. .get_starget_node_name = qla2x00_get_starget_node_name,
  1211. .show_starget_node_name = 1,
  1212. .get_starget_port_name = qla2x00_get_starget_port_name,
  1213. .show_starget_port_name = 1,
  1214. .get_starget_port_id = qla2x00_get_starget_port_id,
  1215. .show_starget_port_id = 1,
  1216. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1217. .show_rport_dev_loss_tmo = 1,
  1218. .issue_fc_host_lip = qla2x00_issue_lip,
  1219. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1220. .terminate_rport_io = qla2x00_terminate_rport_io,
  1221. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1222. .vport_create = qla24xx_vport_create,
  1223. .vport_disable = qla24xx_vport_disable,
  1224. .vport_delete = qla24xx_vport_delete,
  1225. };
  1226. struct fc_function_template qla2xxx_transport_vport_functions = {
  1227. .show_host_node_name = 1,
  1228. .show_host_port_name = 1,
  1229. .show_host_supported_classes = 1,
  1230. .get_host_port_id = qla2x00_get_host_port_id,
  1231. .show_host_port_id = 1,
  1232. .get_host_speed = qla2x00_get_host_speed,
  1233. .show_host_speed = 1,
  1234. .get_host_port_type = qla2x00_get_host_port_type,
  1235. .show_host_port_type = 1,
  1236. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1237. .show_host_symbolic_name = 1,
  1238. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1239. .show_host_system_hostname = 1,
  1240. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1241. .show_host_fabric_name = 1,
  1242. .get_host_port_state = qla2x00_get_host_port_state,
  1243. .show_host_port_state = 1,
  1244. .dd_fcrport_size = sizeof(struct fc_port *),
  1245. .show_rport_supported_classes = 1,
  1246. .get_starget_node_name = qla2x00_get_starget_node_name,
  1247. .show_starget_node_name = 1,
  1248. .get_starget_port_name = qla2x00_get_starget_port_name,
  1249. .show_starget_port_name = 1,
  1250. .get_starget_port_id = qla2x00_get_starget_port_id,
  1251. .show_starget_port_id = 1,
  1252. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1253. .show_rport_dev_loss_tmo = 1,
  1254. .issue_fc_host_lip = qla2x00_issue_lip,
  1255. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1256. .terminate_rport_io = qla2x00_terminate_rport_io,
  1257. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1258. };
  1259. void
  1260. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1261. {
  1262. struct qla_hw_data *ha = vha->hw;
  1263. u32 speed = FC_PORTSPEED_UNKNOWN;
  1264. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1265. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1266. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  1267. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1268. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1269. if (IS_QLA81XX(ha))
  1270. speed = FC_PORTSPEED_10GBIT;
  1271. else if (IS_QLA25XX(ha))
  1272. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1273. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1274. else if (IS_QLA24XX_TYPE(ha))
  1275. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1276. FC_PORTSPEED_1GBIT;
  1277. else if (IS_QLA23XX(ha))
  1278. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1279. else
  1280. speed = FC_PORTSPEED_1GBIT;
  1281. fc_host_supported_speeds(vha->host) = speed;
  1282. }