qla_attr.c 33 KB

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