qla_attr.c 36 KB

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