qla_attr.c 34 KB

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