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 == (ha->flt_region_boot * 4) ||
  249. start == (ha->flt_region_fw * 4))
  250. valid = 1;
  251. else if (IS_QLA25XX(ha) &&
  252. start == (ha->flt_region_vpd_nvram * 4))
  253. valid = 1;
  254. if (!valid) {
  255. qla_printk(KERN_WARNING, ha,
  256. "Invalid start region 0x%x/0x%x.\n", start, size);
  257. return -EINVAL;
  258. }
  259. ha->optrom_region_start = start;
  260. ha->optrom_region_size = start + size > ha->optrom_size ?
  261. ha->optrom_size - start : size;
  262. ha->optrom_state = QLA_SWRITING;
  263. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  264. if (ha->optrom_buffer == NULL) {
  265. qla_printk(KERN_WARNING, ha,
  266. "Unable to allocate memory for optrom update "
  267. "(%x).\n", ha->optrom_region_size);
  268. ha->optrom_state = QLA_SWAITING;
  269. return count;
  270. }
  271. DEBUG2(qla_printk(KERN_INFO, ha,
  272. "Staging flash region write -- 0x%x/0x%x.\n",
  273. ha->optrom_region_start, ha->optrom_region_size));
  274. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  275. break;
  276. case 3:
  277. if (ha->optrom_state != QLA_SWRITING)
  278. break;
  279. DEBUG2(qla_printk(KERN_INFO, ha,
  280. "Writing flash region -- 0x%x/0x%x.\n",
  281. ha->optrom_region_start, ha->optrom_region_size));
  282. ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
  283. ha->optrom_region_start, ha->optrom_region_size);
  284. break;
  285. default:
  286. count = -EINVAL;
  287. }
  288. return count;
  289. }
  290. static struct bin_attribute sysfs_optrom_ctl_attr = {
  291. .attr = {
  292. .name = "optrom_ctl",
  293. .mode = S_IWUSR,
  294. },
  295. .size = 0,
  296. .write = qla2x00_sysfs_write_optrom_ctl,
  297. };
  298. static ssize_t
  299. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  300. struct bin_attribute *bin_attr,
  301. char *buf, loff_t off, size_t count)
  302. {
  303. struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
  304. struct device, kobj)));
  305. if (!capable(CAP_SYS_ADMIN))
  306. return 0;
  307. /* Read NVRAM data from cache. */
  308. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  309. }
  310. static ssize_t
  311. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  312. struct bin_attribute *bin_attr,
  313. char *buf, loff_t off, size_t count)
  314. {
  315. struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
  316. struct device, kobj)));
  317. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
  318. return 0;
  319. /* Write NVRAM. */
  320. ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
  321. ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  322. return count;
  323. }
  324. static struct bin_attribute sysfs_vpd_attr = {
  325. .attr = {
  326. .name = "vpd",
  327. .mode = S_IRUSR | S_IWUSR,
  328. },
  329. .size = 0,
  330. .read = qla2x00_sysfs_read_vpd,
  331. .write = qla2x00_sysfs_write_vpd,
  332. };
  333. static ssize_t
  334. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  335. struct bin_attribute *bin_attr,
  336. char *buf, loff_t off, size_t count)
  337. {
  338. struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
  339. struct device, kobj)));
  340. uint16_t iter, addr, offset;
  341. int rval;
  342. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  343. return 0;
  344. if (ha->sfp_data)
  345. goto do_read;
  346. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  347. &ha->sfp_data_dma);
  348. if (!ha->sfp_data) {
  349. qla_printk(KERN_WARNING, ha,
  350. "Unable to allocate memory for SFP read-data.\n");
  351. return 0;
  352. }
  353. do_read:
  354. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  355. addr = 0xa0;
  356. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  357. iter++, offset += SFP_BLOCK_SIZE) {
  358. if (iter == 4) {
  359. /* Skip to next device address. */
  360. addr = 0xa2;
  361. offset = 0;
  362. }
  363. rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
  364. SFP_BLOCK_SIZE);
  365. if (rval != QLA_SUCCESS) {
  366. qla_printk(KERN_WARNING, ha,
  367. "Unable to read SFP data (%x/%x/%x).\n", rval,
  368. addr, offset);
  369. count = 0;
  370. break;
  371. }
  372. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  373. buf += SFP_BLOCK_SIZE;
  374. }
  375. return count;
  376. }
  377. static struct bin_attribute sysfs_sfp_attr = {
  378. .attr = {
  379. .name = "sfp",
  380. .mode = S_IRUSR | S_IWUSR,
  381. },
  382. .size = SFP_DEV_SIZE * 2,
  383. .read = qla2x00_sysfs_read_sfp,
  384. };
  385. static struct sysfs_entry {
  386. char *name;
  387. struct bin_attribute *attr;
  388. int is4GBp_only;
  389. } bin_file_entries[] = {
  390. { "fw_dump", &sysfs_fw_dump_attr, },
  391. { "nvram", &sysfs_nvram_attr, },
  392. { "optrom", &sysfs_optrom_attr, },
  393. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  394. { "vpd", &sysfs_vpd_attr, 1 },
  395. { "sfp", &sysfs_sfp_attr, 1 },
  396. { NULL },
  397. };
  398. void
  399. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
  400. {
  401. struct Scsi_Host *host = ha->host;
  402. struct sysfs_entry *iter;
  403. int ret;
  404. for (iter = bin_file_entries; iter->name; iter++) {
  405. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  406. continue;
  407. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  408. iter->attr);
  409. if (ret)
  410. qla_printk(KERN_INFO, ha,
  411. "Unable to create sysfs %s binary attribute "
  412. "(%d).\n", iter->name, ret);
  413. }
  414. }
  415. void
  416. qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
  417. {
  418. struct Scsi_Host *host = ha->host;
  419. struct sysfs_entry *iter;
  420. for (iter = bin_file_entries; iter->name; iter++) {
  421. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  422. continue;
  423. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  424. iter->attr);
  425. }
  426. if (ha->beacon_blink_led == 1)
  427. ha->isp_ops->beacon_off(ha);
  428. }
  429. /* Scsi_Host attributes. */
  430. static ssize_t
  431. qla2x00_drvr_version_show(struct device *dev,
  432. struct device_attribute *attr, char *buf)
  433. {
  434. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  435. }
  436. static ssize_t
  437. qla2x00_fw_version_show(struct device *dev,
  438. struct device_attribute *attr, char *buf)
  439. {
  440. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  441. char fw_str[30];
  442. return snprintf(buf, PAGE_SIZE, "%s\n",
  443. ha->isp_ops->fw_version_str(ha, fw_str));
  444. }
  445. static ssize_t
  446. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  447. char *buf)
  448. {
  449. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  450. uint32_t sn;
  451. if (IS_FWI2_CAPABLE(ha)) {
  452. qla2xxx_get_vpd_field(ha, "SN", buf, PAGE_SIZE);
  453. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  454. }
  455. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  456. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  457. sn % 100000);
  458. }
  459. static ssize_t
  460. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  461. char *buf)
  462. {
  463. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  464. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  465. }
  466. static ssize_t
  467. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  468. char *buf)
  469. {
  470. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  471. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  472. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  473. ha->product_id[3]);
  474. }
  475. static ssize_t
  476. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  477. char *buf)
  478. {
  479. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  480. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  481. }
  482. static ssize_t
  483. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  484. char *buf)
  485. {
  486. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  487. return snprintf(buf, PAGE_SIZE, "%s\n",
  488. ha->model_desc ? ha->model_desc: "");
  489. }
  490. static ssize_t
  491. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  492. char *buf)
  493. {
  494. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  495. char pci_info[30];
  496. return snprintf(buf, PAGE_SIZE, "%s\n",
  497. ha->isp_ops->pci_info_str(ha, pci_info));
  498. }
  499. static ssize_t
  500. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  501. char *buf)
  502. {
  503. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  504. int len = 0;
  505. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  506. atomic_read(&ha->loop_state) == LOOP_DEAD)
  507. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  508. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  509. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  510. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  511. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  512. else {
  513. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  514. switch (ha->current_topology) {
  515. case ISP_CFG_NL:
  516. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  517. break;
  518. case ISP_CFG_FL:
  519. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  520. break;
  521. case ISP_CFG_N:
  522. len += snprintf(buf + len, PAGE_SIZE-len,
  523. "N_Port to N_Port\n");
  524. break;
  525. case ISP_CFG_F:
  526. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  527. break;
  528. default:
  529. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  530. break;
  531. }
  532. }
  533. return len;
  534. }
  535. static ssize_t
  536. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  537. char *buf)
  538. {
  539. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  540. int len = 0;
  541. switch (ha->zio_mode) {
  542. case QLA_ZIO_MODE_6:
  543. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  544. break;
  545. case QLA_ZIO_DISABLED:
  546. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  547. break;
  548. }
  549. return len;
  550. }
  551. static ssize_t
  552. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  553. const char *buf, size_t count)
  554. {
  555. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  556. int val = 0;
  557. uint16_t zio_mode;
  558. if (!IS_ZIO_SUPPORTED(ha))
  559. return -ENOTSUPP;
  560. if (sscanf(buf, "%d", &val) != 1)
  561. return -EINVAL;
  562. if (val)
  563. zio_mode = QLA_ZIO_MODE_6;
  564. else
  565. zio_mode = QLA_ZIO_DISABLED;
  566. /* Update per-hba values and queue a reset. */
  567. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  568. ha->zio_mode = zio_mode;
  569. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  570. }
  571. return strlen(buf);
  572. }
  573. static ssize_t
  574. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  575. char *buf)
  576. {
  577. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  578. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  579. }
  580. static ssize_t
  581. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  582. const char *buf, size_t count)
  583. {
  584. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  585. int val = 0;
  586. uint16_t zio_timer;
  587. if (sscanf(buf, "%d", &val) != 1)
  588. return -EINVAL;
  589. if (val > 25500 || val < 100)
  590. return -ERANGE;
  591. zio_timer = (uint16_t)(val / 100);
  592. ha->zio_timer = zio_timer;
  593. return strlen(buf);
  594. }
  595. static ssize_t
  596. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  597. char *buf)
  598. {
  599. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  600. int len = 0;
  601. if (ha->beacon_blink_led)
  602. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  603. else
  604. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  605. return len;
  606. }
  607. static ssize_t
  608. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  609. const char *buf, size_t count)
  610. {
  611. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  612. int val = 0;
  613. int rval;
  614. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  615. return -EPERM;
  616. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  617. qla_printk(KERN_WARNING, ha,
  618. "Abort ISP active -- ignoring beacon request.\n");
  619. return -EBUSY;
  620. }
  621. if (sscanf(buf, "%d", &val) != 1)
  622. return -EINVAL;
  623. if (val)
  624. rval = ha->isp_ops->beacon_on(ha);
  625. else
  626. rval = ha->isp_ops->beacon_off(ha);
  627. if (rval != QLA_SUCCESS)
  628. count = 0;
  629. return count;
  630. }
  631. static ssize_t
  632. qla2x00_optrom_bios_version_show(struct device *dev,
  633. struct device_attribute *attr, char *buf)
  634. {
  635. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  636. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  637. ha->bios_revision[0]);
  638. }
  639. static ssize_t
  640. qla2x00_optrom_efi_version_show(struct device *dev,
  641. struct device_attribute *attr, char *buf)
  642. {
  643. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  644. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  645. ha->efi_revision[0]);
  646. }
  647. static ssize_t
  648. qla2x00_optrom_fcode_version_show(struct device *dev,
  649. struct device_attribute *attr, char *buf)
  650. {
  651. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  652. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  653. ha->fcode_revision[0]);
  654. }
  655. static ssize_t
  656. qla2x00_optrom_fw_version_show(struct device *dev,
  657. struct device_attribute *attr, char *buf)
  658. {
  659. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  660. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  661. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  662. ha->fw_revision[3]);
  663. }
  664. static ssize_t
  665. qla2x00_total_isp_aborts_show(struct device *dev,
  666. struct device_attribute *attr, char *buf)
  667. {
  668. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  669. return snprintf(buf, PAGE_SIZE, "%d\n",
  670. ha->qla_stats.total_isp_aborts);
  671. }
  672. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  673. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  674. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  675. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  676. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  677. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  678. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  679. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  680. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  681. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  682. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  683. qla2x00_zio_timer_store);
  684. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  685. qla2x00_beacon_store);
  686. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  687. qla2x00_optrom_bios_version_show, NULL);
  688. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  689. qla2x00_optrom_efi_version_show, NULL);
  690. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  691. qla2x00_optrom_fcode_version_show, NULL);
  692. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  693. NULL);
  694. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  695. NULL);
  696. struct device_attribute *qla2x00_host_attrs[] = {
  697. &dev_attr_driver_version,
  698. &dev_attr_fw_version,
  699. &dev_attr_serial_num,
  700. &dev_attr_isp_name,
  701. &dev_attr_isp_id,
  702. &dev_attr_model_name,
  703. &dev_attr_model_desc,
  704. &dev_attr_pci_info,
  705. &dev_attr_link_state,
  706. &dev_attr_zio,
  707. &dev_attr_zio_timer,
  708. &dev_attr_beacon,
  709. &dev_attr_optrom_bios_version,
  710. &dev_attr_optrom_efi_version,
  711. &dev_attr_optrom_fcode_version,
  712. &dev_attr_optrom_fw_version,
  713. &dev_attr_total_isp_aborts,
  714. NULL,
  715. };
  716. /* Host attributes. */
  717. static void
  718. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  719. {
  720. scsi_qla_host_t *ha = shost_priv(shost);
  721. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  722. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  723. }
  724. static void
  725. qla2x00_get_host_speed(struct Scsi_Host *shost)
  726. {
  727. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  728. u32 speed = FC_PORTSPEED_UNKNOWN;
  729. switch (ha->link_data_rate) {
  730. case PORT_SPEED_1GB:
  731. speed = FC_PORTSPEED_1GBIT;
  732. break;
  733. case PORT_SPEED_2GB:
  734. speed = FC_PORTSPEED_2GBIT;
  735. break;
  736. case PORT_SPEED_4GB:
  737. speed = FC_PORTSPEED_4GBIT;
  738. break;
  739. case PORT_SPEED_8GB:
  740. speed = FC_PORTSPEED_8GBIT;
  741. break;
  742. }
  743. fc_host_speed(shost) = speed;
  744. }
  745. static void
  746. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  747. {
  748. scsi_qla_host_t *ha = shost_priv(shost);
  749. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  750. if (ha->parent) {
  751. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  752. return;
  753. }
  754. switch (ha->current_topology) {
  755. case ISP_CFG_NL:
  756. port_type = FC_PORTTYPE_LPORT;
  757. break;
  758. case ISP_CFG_FL:
  759. port_type = FC_PORTTYPE_NLPORT;
  760. break;
  761. case ISP_CFG_N:
  762. port_type = FC_PORTTYPE_PTP;
  763. break;
  764. case ISP_CFG_F:
  765. port_type = FC_PORTTYPE_NPORT;
  766. break;
  767. }
  768. fc_host_port_type(shost) = port_type;
  769. }
  770. static void
  771. qla2x00_get_starget_node_name(struct scsi_target *starget)
  772. {
  773. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  774. scsi_qla_host_t *ha = shost_priv(host);
  775. fc_port_t *fcport;
  776. u64 node_name = 0;
  777. list_for_each_entry(fcport, &ha->fcports, list) {
  778. if (fcport->rport &&
  779. starget->id == fcport->rport->scsi_target_id) {
  780. node_name = wwn_to_u64(fcport->node_name);
  781. break;
  782. }
  783. }
  784. fc_starget_node_name(starget) = node_name;
  785. }
  786. static void
  787. qla2x00_get_starget_port_name(struct scsi_target *starget)
  788. {
  789. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  790. scsi_qla_host_t *ha = shost_priv(host);
  791. fc_port_t *fcport;
  792. u64 port_name = 0;
  793. list_for_each_entry(fcport, &ha->fcports, list) {
  794. if (fcport->rport &&
  795. starget->id == fcport->rport->scsi_target_id) {
  796. port_name = wwn_to_u64(fcport->port_name);
  797. break;
  798. }
  799. }
  800. fc_starget_port_name(starget) = port_name;
  801. }
  802. static void
  803. qla2x00_get_starget_port_id(struct scsi_target *starget)
  804. {
  805. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  806. scsi_qla_host_t *ha = shost_priv(host);
  807. fc_port_t *fcport;
  808. uint32_t port_id = ~0U;
  809. list_for_each_entry(fcport, &ha->fcports, list) {
  810. if (fcport->rport &&
  811. starget->id == fcport->rport->scsi_target_id) {
  812. port_id = fcport->d_id.b.domain << 16 |
  813. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  814. break;
  815. }
  816. }
  817. fc_starget_port_id(starget) = port_id;
  818. }
  819. static void
  820. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  821. {
  822. if (timeout)
  823. rport->dev_loss_tmo = timeout;
  824. else
  825. rport->dev_loss_tmo = 1;
  826. }
  827. static void
  828. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  829. {
  830. struct Scsi_Host *host = rport_to_shost(rport);
  831. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  832. qla2x00_abort_fcport_cmds(fcport);
  833. /*
  834. * Transport has effectively 'deleted' the rport, clear
  835. * all local references.
  836. */
  837. spin_lock_irq(host->host_lock);
  838. fcport->rport = NULL;
  839. *((fc_port_t **)rport->dd_data) = NULL;
  840. spin_unlock_irq(host->host_lock);
  841. }
  842. static void
  843. qla2x00_terminate_rport_io(struct fc_rport *rport)
  844. {
  845. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  846. /*
  847. * At this point all fcport's software-states are cleared. Perform any
  848. * final cleanup of firmware resources (PCBs and XCBs).
  849. */
  850. if (fcport->loop_id != FC_NO_LOOP_ID) {
  851. fcport->ha->isp_ops->fabric_logout(fcport->ha, fcport->loop_id,
  852. fcport->d_id.b.domain, fcport->d_id.b.area,
  853. fcport->d_id.b.al_pa);
  854. fcport->loop_id = FC_NO_LOOP_ID;
  855. }
  856. qla2x00_abort_fcport_cmds(fcport);
  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. }