qla_attr.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2005 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. int qla24xx_vport_disable(struct fc_vport *, bool);
  11. /* SYSFS attributes --------------------------------------------------------- */
  12. static ssize_t
  13. qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off,
  14. size_t count)
  15. {
  16. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  17. struct device, kobj)));
  18. char *rbuf = (char *)ha->fw_dump;
  19. if (ha->fw_dump_reading == 0)
  20. return 0;
  21. if (off > ha->fw_dump_len)
  22. return 0;
  23. if (off + count > ha->fw_dump_len)
  24. count = ha->fw_dump_len - off;
  25. memcpy(buf, &rbuf[off], count);
  26. return (count);
  27. }
  28. static ssize_t
  29. qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
  30. size_t count)
  31. {
  32. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  33. struct device, kobj)));
  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", ha->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. ha->host_no);
  53. }
  54. break;
  55. case 2:
  56. qla2x00_alloc_fw_dump(ha);
  57. break;
  58. }
  59. return (count);
  60. }
  61. static struct bin_attribute sysfs_fw_dump_attr = {
  62. .attr = {
  63. .name = "fw_dump",
  64. .mode = S_IRUSR | S_IWUSR,
  65. .owner = THIS_MODULE,
  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, char *buf, loff_t off,
  73. size_t count)
  74. {
  75. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  76. struct device, kobj)));
  77. unsigned long flags;
  78. if (!capable(CAP_SYS_ADMIN) || off != 0)
  79. return 0;
  80. /* Read NVRAM. */
  81. spin_lock_irqsave(&ha->hardware_lock, flags);
  82. ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
  83. ha->nvram_size);
  84. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  85. return ha->nvram_size;
  86. }
  87. static ssize_t
  88. qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
  89. size_t count)
  90. {
  91. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  92. struct device, kobj)));
  93. unsigned long flags;
  94. uint16_t cnt;
  95. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
  96. return 0;
  97. /* Checksum NVRAM. */
  98. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  99. uint32_t *iter;
  100. uint32_t chksum;
  101. iter = (uint32_t *)buf;
  102. chksum = 0;
  103. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  104. chksum += le32_to_cpu(*iter++);
  105. chksum = ~chksum + 1;
  106. *iter = cpu_to_le32(chksum);
  107. } else {
  108. uint8_t *iter;
  109. uint8_t chksum;
  110. iter = (uint8_t *)buf;
  111. chksum = 0;
  112. for (cnt = 0; cnt < count - 1; cnt++)
  113. chksum += *iter++;
  114. chksum = ~chksum + 1;
  115. *iter = chksum;
  116. }
  117. /* Write NVRAM. */
  118. spin_lock_irqsave(&ha->hardware_lock, flags);
  119. ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
  120. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  121. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  122. return (count);
  123. }
  124. static struct bin_attribute sysfs_nvram_attr = {
  125. .attr = {
  126. .name = "nvram",
  127. .mode = S_IRUSR | S_IWUSR,
  128. .owner = THIS_MODULE,
  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, char *buf, loff_t off,
  136. size_t count)
  137. {
  138. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  139. struct device, kobj)));
  140. if (ha->optrom_state != QLA_SREADING)
  141. return 0;
  142. if (off > ha->optrom_size)
  143. return 0;
  144. if (off + count > ha->optrom_size)
  145. count = ha->optrom_size - off;
  146. memcpy(buf, &ha->optrom_buffer[off], count);
  147. return count;
  148. }
  149. static ssize_t
  150. qla2x00_sysfs_write_optrom(struct kobject *kobj, char *buf, loff_t off,
  151. size_t count)
  152. {
  153. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  154. struct device, kobj)));
  155. if (ha->optrom_state != QLA_SWRITING)
  156. return -EINVAL;
  157. if (off > ha->optrom_size)
  158. return -ERANGE;
  159. if (off + count > ha->optrom_size)
  160. count = ha->optrom_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. .owner = THIS_MODULE,
  169. },
  170. .size = OPTROM_SIZE_24XX,
  171. .read = qla2x00_sysfs_read_optrom,
  172. .write = qla2x00_sysfs_write_optrom,
  173. };
  174. static ssize_t
  175. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off,
  176. size_t count)
  177. {
  178. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  179. struct device, kobj)));
  180. int val;
  181. if (off)
  182. return 0;
  183. if (sscanf(buf, "%d", &val) != 1)
  184. return -EINVAL;
  185. switch (val) {
  186. case 0:
  187. if (ha->optrom_state != QLA_SREADING &&
  188. ha->optrom_state != QLA_SWRITING)
  189. break;
  190. ha->optrom_state = QLA_SWAITING;
  191. vfree(ha->optrom_buffer);
  192. ha->optrom_buffer = NULL;
  193. break;
  194. case 1:
  195. if (ha->optrom_state != QLA_SWAITING)
  196. break;
  197. ha->optrom_state = QLA_SREADING;
  198. ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
  199. if (ha->optrom_buffer == NULL) {
  200. qla_printk(KERN_WARNING, ha,
  201. "Unable to allocate memory for optrom retrieval "
  202. "(%x).\n", ha->optrom_size);
  203. ha->optrom_state = QLA_SWAITING;
  204. return count;
  205. }
  206. memset(ha->optrom_buffer, 0, ha->optrom_size);
  207. ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0,
  208. ha->optrom_size);
  209. break;
  210. case 2:
  211. if (ha->optrom_state != QLA_SWAITING)
  212. break;
  213. ha->optrom_state = QLA_SWRITING;
  214. ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
  215. if (ha->optrom_buffer == NULL) {
  216. qla_printk(KERN_WARNING, ha,
  217. "Unable to allocate memory for optrom update "
  218. "(%x).\n", ha->optrom_size);
  219. ha->optrom_state = QLA_SWAITING;
  220. return count;
  221. }
  222. memset(ha->optrom_buffer, 0, ha->optrom_size);
  223. break;
  224. case 3:
  225. if (ha->optrom_state != QLA_SWRITING)
  226. break;
  227. ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0,
  228. ha->optrom_size);
  229. break;
  230. }
  231. return count;
  232. }
  233. static struct bin_attribute sysfs_optrom_ctl_attr = {
  234. .attr = {
  235. .name = "optrom_ctl",
  236. .mode = S_IWUSR,
  237. .owner = THIS_MODULE,
  238. },
  239. .size = 0,
  240. .write = qla2x00_sysfs_write_optrom_ctl,
  241. };
  242. static ssize_t
  243. qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off,
  244. size_t count)
  245. {
  246. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  247. struct device, kobj)));
  248. unsigned long flags;
  249. if (!capable(CAP_SYS_ADMIN) || off != 0)
  250. return 0;
  251. /* Read NVRAM. */
  252. spin_lock_irqsave(&ha->hardware_lock, flags);
  253. ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size);
  254. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  255. return ha->vpd_size;
  256. }
  257. static ssize_t
  258. qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off,
  259. size_t count)
  260. {
  261. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  262. struct device, kobj)));
  263. unsigned long flags;
  264. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
  265. return 0;
  266. /* Write NVRAM. */
  267. spin_lock_irqsave(&ha->hardware_lock, flags);
  268. ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
  269. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  270. return count;
  271. }
  272. static struct bin_attribute sysfs_vpd_attr = {
  273. .attr = {
  274. .name = "vpd",
  275. .mode = S_IRUSR | S_IWUSR,
  276. .owner = THIS_MODULE,
  277. },
  278. .size = 0,
  279. .read = qla2x00_sysfs_read_vpd,
  280. .write = qla2x00_sysfs_write_vpd,
  281. };
  282. static ssize_t
  283. qla2x00_sysfs_read_sfp(struct kobject *kobj, char *buf, loff_t off,
  284. size_t count)
  285. {
  286. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  287. struct device, kobj)));
  288. uint16_t iter, addr, offset;
  289. int rval;
  290. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  291. return 0;
  292. addr = 0xa0;
  293. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  294. iter++, offset += SFP_BLOCK_SIZE) {
  295. if (iter == 4) {
  296. /* Skip to next device address. */
  297. addr = 0xa2;
  298. offset = 0;
  299. }
  300. rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
  301. SFP_BLOCK_SIZE);
  302. if (rval != QLA_SUCCESS) {
  303. qla_printk(KERN_WARNING, ha,
  304. "Unable to read SFP data (%x/%x/%x).\n", rval,
  305. addr, offset);
  306. count = 0;
  307. break;
  308. }
  309. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  310. buf += SFP_BLOCK_SIZE;
  311. }
  312. return count;
  313. }
  314. static struct bin_attribute sysfs_sfp_attr = {
  315. .attr = {
  316. .name = "sfp",
  317. .mode = S_IRUSR | S_IWUSR,
  318. .owner = THIS_MODULE,
  319. },
  320. .size = SFP_DEV_SIZE * 2,
  321. .read = qla2x00_sysfs_read_sfp,
  322. };
  323. static struct sysfs_entry {
  324. char *name;
  325. struct bin_attribute *attr;
  326. int is4GBp_only;
  327. } bin_file_entries[] = {
  328. { "fw_dump", &sysfs_fw_dump_attr, },
  329. { "nvram", &sysfs_nvram_attr, },
  330. { "optrom", &sysfs_optrom_attr, },
  331. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  332. { "vpd", &sysfs_vpd_attr, 1 },
  333. { "sfp", &sysfs_sfp_attr, 1 },
  334. { NULL },
  335. };
  336. void
  337. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
  338. {
  339. struct Scsi_Host *host = ha->host;
  340. struct sysfs_entry *iter;
  341. int ret;
  342. for (iter = bin_file_entries; iter->name; iter++) {
  343. if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)))
  344. continue;
  345. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  346. iter->attr);
  347. if (ret)
  348. qla_printk(KERN_INFO, ha,
  349. "Unable to create sysfs %s binary attribute "
  350. "(%d).\n", iter->name, ret);
  351. }
  352. }
  353. void
  354. qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
  355. {
  356. struct Scsi_Host *host = ha->host;
  357. struct sysfs_entry *iter;
  358. for (iter = bin_file_entries; iter->name; iter++) {
  359. if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)))
  360. continue;
  361. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  362. iter->attr);
  363. }
  364. if (ha->beacon_blink_led == 1)
  365. ha->isp_ops.beacon_off(ha);
  366. }
  367. /* Scsi_Host attributes. */
  368. static ssize_t
  369. qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
  370. {
  371. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  372. }
  373. static ssize_t
  374. qla2x00_fw_version_show(struct class_device *cdev, char *buf)
  375. {
  376. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  377. char fw_str[30];
  378. return snprintf(buf, PAGE_SIZE, "%s\n",
  379. ha->isp_ops.fw_version_str(ha, fw_str));
  380. }
  381. static ssize_t
  382. qla2x00_serial_num_show(struct class_device *cdev, char *buf)
  383. {
  384. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  385. uint32_t sn;
  386. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  387. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  388. sn % 100000);
  389. }
  390. static ssize_t
  391. qla2x00_isp_name_show(struct class_device *cdev, char *buf)
  392. {
  393. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  394. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  395. }
  396. static ssize_t
  397. qla2x00_isp_id_show(struct class_device *cdev, char *buf)
  398. {
  399. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  400. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  401. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  402. ha->product_id[3]);
  403. }
  404. static ssize_t
  405. qla2x00_model_name_show(struct class_device *cdev, char *buf)
  406. {
  407. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  408. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  409. }
  410. static ssize_t
  411. qla2x00_model_desc_show(struct class_device *cdev, char *buf)
  412. {
  413. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  414. return snprintf(buf, PAGE_SIZE, "%s\n",
  415. ha->model_desc ? ha->model_desc: "");
  416. }
  417. static ssize_t
  418. qla2x00_pci_info_show(struct class_device *cdev, char *buf)
  419. {
  420. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  421. char pci_info[30];
  422. return snprintf(buf, PAGE_SIZE, "%s\n",
  423. ha->isp_ops.pci_info_str(ha, pci_info));
  424. }
  425. static ssize_t
  426. qla2x00_state_show(struct class_device *cdev, char *buf)
  427. {
  428. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  429. int len = 0;
  430. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  431. atomic_read(&ha->loop_state) == LOOP_DEAD)
  432. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  433. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  434. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  435. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  436. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  437. else {
  438. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  439. switch (ha->current_topology) {
  440. case ISP_CFG_NL:
  441. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  442. break;
  443. case ISP_CFG_FL:
  444. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  445. break;
  446. case ISP_CFG_N:
  447. len += snprintf(buf + len, PAGE_SIZE-len,
  448. "N_Port to N_Port\n");
  449. break;
  450. case ISP_CFG_F:
  451. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  452. break;
  453. default:
  454. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  455. break;
  456. }
  457. }
  458. return len;
  459. }
  460. static ssize_t
  461. qla2x00_zio_show(struct class_device *cdev, char *buf)
  462. {
  463. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  464. int len = 0;
  465. switch (ha->zio_mode) {
  466. case QLA_ZIO_MODE_6:
  467. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  468. break;
  469. case QLA_ZIO_DISABLED:
  470. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  471. break;
  472. }
  473. return len;
  474. }
  475. static ssize_t
  476. qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
  477. {
  478. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  479. int val = 0;
  480. uint16_t zio_mode;
  481. if (!IS_ZIO_SUPPORTED(ha))
  482. return -ENOTSUPP;
  483. if (sscanf(buf, "%d", &val) != 1)
  484. return -EINVAL;
  485. if (val)
  486. zio_mode = QLA_ZIO_MODE_6;
  487. else
  488. zio_mode = QLA_ZIO_DISABLED;
  489. /* Update per-hba values and queue a reset. */
  490. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  491. ha->zio_mode = zio_mode;
  492. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  493. }
  494. return strlen(buf);
  495. }
  496. static ssize_t
  497. qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
  498. {
  499. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  500. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  501. }
  502. static ssize_t
  503. qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
  504. size_t count)
  505. {
  506. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  507. int val = 0;
  508. uint16_t zio_timer;
  509. if (sscanf(buf, "%d", &val) != 1)
  510. return -EINVAL;
  511. if (val > 25500 || val < 100)
  512. return -ERANGE;
  513. zio_timer = (uint16_t)(val / 100);
  514. ha->zio_timer = zio_timer;
  515. return strlen(buf);
  516. }
  517. static ssize_t
  518. qla2x00_beacon_show(struct class_device *cdev, char *buf)
  519. {
  520. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  521. int len = 0;
  522. if (ha->beacon_blink_led)
  523. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  524. else
  525. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  526. return len;
  527. }
  528. static ssize_t
  529. qla2x00_beacon_store(struct class_device *cdev, const char *buf,
  530. size_t count)
  531. {
  532. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  533. int val = 0;
  534. int rval;
  535. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  536. return -EPERM;
  537. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  538. qla_printk(KERN_WARNING, ha,
  539. "Abort ISP active -- ignoring beacon request.\n");
  540. return -EBUSY;
  541. }
  542. if (sscanf(buf, "%d", &val) != 1)
  543. return -EINVAL;
  544. if (val)
  545. rval = ha->isp_ops.beacon_on(ha);
  546. else
  547. rval = ha->isp_ops.beacon_off(ha);
  548. if (rval != QLA_SUCCESS)
  549. count = 0;
  550. return count;
  551. }
  552. static ssize_t
  553. qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
  554. {
  555. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  556. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  557. ha->bios_revision[0]);
  558. }
  559. static ssize_t
  560. qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
  561. {
  562. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  563. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  564. ha->efi_revision[0]);
  565. }
  566. static ssize_t
  567. qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
  568. {
  569. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  570. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  571. ha->fcode_revision[0]);
  572. }
  573. static ssize_t
  574. qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
  575. {
  576. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  577. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  578. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  579. ha->fw_revision[3]);
  580. }
  581. static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
  582. NULL);
  583. static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  584. static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  585. static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  586. static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  587. static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  588. static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  589. static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  590. static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
  591. static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
  592. qla2x00_zio_store);
  593. static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  594. qla2x00_zio_timer_store);
  595. static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  596. qla2x00_beacon_store);
  597. static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  598. qla2x00_optrom_bios_version_show, NULL);
  599. static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  600. qla2x00_optrom_efi_version_show, NULL);
  601. static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  602. qla2x00_optrom_fcode_version_show, NULL);
  603. static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
  604. qla2x00_optrom_fw_version_show, NULL);
  605. struct class_device_attribute *qla2x00_host_attrs[] = {
  606. &class_device_attr_driver_version,
  607. &class_device_attr_fw_version,
  608. &class_device_attr_serial_num,
  609. &class_device_attr_isp_name,
  610. &class_device_attr_isp_id,
  611. &class_device_attr_model_name,
  612. &class_device_attr_model_desc,
  613. &class_device_attr_pci_info,
  614. &class_device_attr_state,
  615. &class_device_attr_zio,
  616. &class_device_attr_zio_timer,
  617. &class_device_attr_beacon,
  618. &class_device_attr_optrom_bios_version,
  619. &class_device_attr_optrom_efi_version,
  620. &class_device_attr_optrom_fcode_version,
  621. &class_device_attr_optrom_fw_version,
  622. NULL,
  623. };
  624. /* Host attributes. */
  625. static void
  626. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  627. {
  628. scsi_qla_host_t *ha = to_qla_host(shost);
  629. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  630. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  631. }
  632. static void
  633. qla2x00_get_host_speed(struct Scsi_Host *shost)
  634. {
  635. scsi_qla_host_t *ha = to_qla_host(shost);
  636. uint32_t speed = 0;
  637. switch (ha->link_data_rate) {
  638. case PORT_SPEED_1GB:
  639. speed = 1;
  640. break;
  641. case PORT_SPEED_2GB:
  642. speed = 2;
  643. break;
  644. case PORT_SPEED_4GB:
  645. speed = 4;
  646. break;
  647. }
  648. fc_host_speed(shost) = speed;
  649. }
  650. static void
  651. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  652. {
  653. scsi_qla_host_t *ha = to_qla_host(shost);
  654. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  655. switch (ha->current_topology) {
  656. case ISP_CFG_NL:
  657. port_type = FC_PORTTYPE_LPORT;
  658. break;
  659. case ISP_CFG_FL:
  660. port_type = FC_PORTTYPE_NLPORT;
  661. break;
  662. case ISP_CFG_N:
  663. port_type = FC_PORTTYPE_PTP;
  664. break;
  665. case ISP_CFG_F:
  666. port_type = FC_PORTTYPE_NPORT;
  667. break;
  668. }
  669. fc_host_port_type(shost) = port_type;
  670. }
  671. static void
  672. qla2x00_get_starget_node_name(struct scsi_target *starget)
  673. {
  674. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  675. scsi_qla_host_t *ha = to_qla_host(host);
  676. fc_port_t *fcport;
  677. u64 node_name = 0;
  678. list_for_each_entry(fcport, &ha->fcports, list) {
  679. if (starget->id == fcport->os_target_id) {
  680. node_name = wwn_to_u64(fcport->node_name);
  681. break;
  682. }
  683. }
  684. fc_starget_node_name(starget) = node_name;
  685. }
  686. static void
  687. qla2x00_get_starget_port_name(struct scsi_target *starget)
  688. {
  689. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  690. scsi_qla_host_t *ha = to_qla_host(host);
  691. fc_port_t *fcport;
  692. u64 port_name = 0;
  693. list_for_each_entry(fcport, &ha->fcports, list) {
  694. if (starget->id == fcport->os_target_id) {
  695. port_name = wwn_to_u64(fcport->port_name);
  696. break;
  697. }
  698. }
  699. fc_starget_port_name(starget) = port_name;
  700. }
  701. static void
  702. qla2x00_get_starget_port_id(struct scsi_target *starget)
  703. {
  704. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  705. scsi_qla_host_t *ha = to_qla_host(host);
  706. fc_port_t *fcport;
  707. uint32_t port_id = ~0U;
  708. list_for_each_entry(fcport, &ha->fcports, list) {
  709. if (starget->id == fcport->os_target_id) {
  710. port_id = fcport->d_id.b.domain << 16 |
  711. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  712. break;
  713. }
  714. }
  715. fc_starget_port_id(starget) = port_id;
  716. }
  717. static void
  718. qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
  719. {
  720. struct Scsi_Host *host = rport_to_shost(rport);
  721. scsi_qla_host_t *ha = to_qla_host(host);
  722. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  723. }
  724. static void
  725. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  726. {
  727. struct Scsi_Host *host = rport_to_shost(rport);
  728. scsi_qla_host_t *ha = to_qla_host(host);
  729. if (timeout)
  730. ha->port_down_retry_count = timeout;
  731. else
  732. ha->port_down_retry_count = 1;
  733. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  734. }
  735. static int
  736. qla2x00_issue_lip(struct Scsi_Host *shost)
  737. {
  738. scsi_qla_host_t *ha = to_qla_host(shost);
  739. set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
  740. return 0;
  741. }
  742. static struct fc_host_statistics *
  743. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  744. {
  745. scsi_qla_host_t *ha = to_qla_host(shost);
  746. int rval;
  747. uint16_t mb_stat[1];
  748. link_stat_t stat_buf;
  749. struct fc_host_statistics *pfc_host_stat;
  750. rval = QLA_FUNCTION_FAILED;
  751. pfc_host_stat = &ha->fc_host_stat;
  752. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  753. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  754. rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
  755. sizeof(stat_buf) / 4, mb_stat);
  756. } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
  757. !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
  758. !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
  759. !ha->dpc_active) {
  760. /* Must be in a 'READY' state for statistics retrieval. */
  761. rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
  762. mb_stat);
  763. }
  764. if (rval != QLA_SUCCESS)
  765. goto done;
  766. pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
  767. pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
  768. pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
  769. pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
  770. pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
  771. pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
  772. done:
  773. return pfc_host_stat;
  774. }
  775. static void
  776. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  777. {
  778. scsi_qla_host_t *ha = to_qla_host(shost);
  779. qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
  780. }
  781. static void
  782. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  783. {
  784. scsi_qla_host_t *ha = to_qla_host(shost);
  785. set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
  786. }
  787. static void
  788. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  789. {
  790. scsi_qla_host_t *ha = to_qla_host(shost);
  791. u64 node_name;
  792. if (ha->device_flags & SWITCH_FOUND)
  793. node_name = wwn_to_u64(ha->fabric_node_name);
  794. else
  795. node_name = wwn_to_u64(ha->node_name);
  796. fc_host_fabric_name(shost) = node_name;
  797. }
  798. static void
  799. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  800. {
  801. scsi_qla_host_t *ha = to_qla_host(shost);
  802. if (!ha->flags.online)
  803. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  804. else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
  805. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  806. else
  807. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  808. }
  809. static int
  810. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  811. {
  812. int ret = 0;
  813. scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
  814. scsi_qla_host_t *vha;
  815. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  816. if (ret) {
  817. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  818. "status %x\n", ret));
  819. return (ret);
  820. }
  821. vha = qla24xx_create_vhost(fc_vport);
  822. if (vha == NULL) {
  823. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  824. vha));
  825. return FC_VPORT_FAILED;
  826. }
  827. if (disable) {
  828. atomic_set(&vha->vp_state, VP_OFFLINE);
  829. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  830. } else
  831. atomic_set(&vha->vp_state, VP_FAILED);
  832. /* ready to create vport */
  833. qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
  834. /* initialized vport states */
  835. atomic_set(&vha->loop_state, LOOP_DOWN);
  836. vha->vp_err_state= VP_ERR_PORTDWN;
  837. vha->vp_prev_err_state= VP_ERR_UNKWN;
  838. /* Check if physical ha port is Up */
  839. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  840. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  841. /* Don't retry or attempt login of this virtual port */
  842. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  843. vha->host_no));
  844. atomic_set(&vha->loop_state, LOOP_DEAD);
  845. if (!disable)
  846. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  847. }
  848. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  849. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  850. vha->host_no, vha->vp_idx));
  851. goto vport_create_failed_2;
  852. }
  853. /* initialize attributes */
  854. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  855. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  856. fc_host_supported_classes(vha->host) =
  857. fc_host_supported_classes(ha->host);
  858. fc_host_supported_speeds(vha->host) =
  859. fc_host_supported_speeds(ha->host);
  860. qla24xx_vport_disable(fc_vport, disable);
  861. return 0;
  862. vport_create_failed_2:
  863. qla24xx_disable_vp(vha);
  864. qla24xx_deallocate_vp_id(vha);
  865. kfree(vha->port_name);
  866. kfree(vha->node_name);
  867. scsi_host_put(vha->host);
  868. return FC_VPORT_FAILED;
  869. }
  870. int
  871. qla24xx_vport_delete(struct fc_vport *fc_vport)
  872. {
  873. scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
  874. scsi_qla_host_t *vha = fc_vport->dd_data;
  875. qla24xx_disable_vp(vha);
  876. qla24xx_deallocate_vp_id(vha);
  877. down(&ha->vport_sem);
  878. ha->cur_vport_count--;
  879. clear_bit(vha->vp_idx, (unsigned long *)ha->vp_idx_map);
  880. up(&ha->vport_sem);
  881. kfree(vha->node_name);
  882. kfree(vha->port_name);
  883. if (vha->timer_active) {
  884. qla2x00_vp_stop_timer(vha);
  885. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  886. "has stopped\n",
  887. vha->host_no, vha->vp_idx, vha));
  888. }
  889. fc_remove_host(vha->host);
  890. scsi_remove_host(vha->host);
  891. scsi_host_put(vha->host);
  892. return 0;
  893. }
  894. int
  895. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  896. {
  897. scsi_qla_host_t *vha = fc_vport->dd_data;
  898. if (disable)
  899. qla24xx_disable_vp(vha);
  900. else
  901. qla24xx_enable_vp(vha);
  902. return 0;
  903. }
  904. struct fc_function_template qla2xxx_transport_functions = {
  905. .show_host_node_name = 1,
  906. .show_host_port_name = 1,
  907. .show_host_supported_classes = 1,
  908. .get_host_port_id = qla2x00_get_host_port_id,
  909. .show_host_port_id = 1,
  910. .get_host_speed = qla2x00_get_host_speed,
  911. .show_host_speed = 1,
  912. .get_host_port_type = qla2x00_get_host_port_type,
  913. .show_host_port_type = 1,
  914. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  915. .show_host_symbolic_name = 1,
  916. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  917. .show_host_system_hostname = 1,
  918. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  919. .show_host_fabric_name = 1,
  920. .get_host_port_state = qla2x00_get_host_port_state,
  921. .show_host_port_state = 1,
  922. .dd_fcrport_size = sizeof(struct fc_port *),
  923. .show_rport_supported_classes = 1,
  924. .get_starget_node_name = qla2x00_get_starget_node_name,
  925. .show_starget_node_name = 1,
  926. .get_starget_port_name = qla2x00_get_starget_port_name,
  927. .show_starget_port_name = 1,
  928. .get_starget_port_id = qla2x00_get_starget_port_id,
  929. .show_starget_port_id = 1,
  930. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  931. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  932. .show_rport_dev_loss_tmo = 1,
  933. .issue_fc_host_lip = qla2x00_issue_lip,
  934. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  935. .vport_create = qla24xx_vport_create,
  936. .vport_disable = qla24xx_vport_disable,
  937. .vport_delete = qla24xx_vport_delete,
  938. };
  939. struct fc_function_template qla2xxx_transport_vport_functions = {
  940. .show_host_node_name = 1,
  941. .show_host_port_name = 1,
  942. .show_host_supported_classes = 1,
  943. .get_host_port_id = qla2x00_get_host_port_id,
  944. .show_host_port_id = 1,
  945. .get_host_speed = qla2x00_get_host_speed,
  946. .show_host_speed = 1,
  947. .get_host_port_type = qla2x00_get_host_port_type,
  948. .show_host_port_type = 1,
  949. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  950. .show_host_symbolic_name = 1,
  951. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  952. .show_host_system_hostname = 1,
  953. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  954. .show_host_fabric_name = 1,
  955. .get_host_port_state = qla2x00_get_host_port_state,
  956. .show_host_port_state = 1,
  957. .dd_fcrport_size = sizeof(struct fc_port *),
  958. .show_rport_supported_classes = 1,
  959. .get_starget_node_name = qla2x00_get_starget_node_name,
  960. .show_starget_node_name = 1,
  961. .get_starget_port_name = qla2x00_get_starget_port_name,
  962. .show_starget_port_name = 1,
  963. .get_starget_port_id = qla2x00_get_starget_port_id,
  964. .show_starget_port_id = 1,
  965. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  966. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  967. .show_rport_dev_loss_tmo = 1,
  968. .issue_fc_host_lip = qla2x00_issue_lip,
  969. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  970. };
  971. void
  972. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  973. {
  974. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  975. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  976. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  977. fc_host_max_npiv_vports(ha->host) = MAX_NUM_VPORT_FABRIC;
  978. fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
  979. }