qla_attr.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  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/vmalloc.h>
  9. /* SYSFS attributes --------------------------------------------------------- */
  10. static ssize_t
  11. qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off,
  12. size_t count)
  13. {
  14. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  15. struct device, kobj)));
  16. char *rbuf = (char *)ha->fw_dump;
  17. if (ha->fw_dump_reading == 0)
  18. return 0;
  19. if (off > ha->fw_dump_len)
  20. return 0;
  21. if (off + count > ha->fw_dump_len)
  22. count = ha->fw_dump_len - off;
  23. memcpy(buf, &rbuf[off], count);
  24. return (count);
  25. }
  26. static ssize_t
  27. qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
  28. size_t count)
  29. {
  30. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  31. struct device, kobj)));
  32. int reading;
  33. if (off != 0)
  34. return (0);
  35. reading = simple_strtol(buf, NULL, 10);
  36. switch (reading) {
  37. case 0:
  38. if (!ha->fw_dump_reading)
  39. break;
  40. qla_printk(KERN_INFO, ha,
  41. "Firmware dump cleared on (%ld).\n", ha->host_no);
  42. ha->fw_dump_reading = 0;
  43. ha->fw_dumped = 0;
  44. break;
  45. case 1:
  46. if (ha->fw_dumped && !ha->fw_dump_reading) {
  47. ha->fw_dump_reading = 1;
  48. qla_printk(KERN_INFO, ha,
  49. "Raw firmware dump ready for read on (%ld).\n",
  50. ha->host_no);
  51. }
  52. break;
  53. case 2:
  54. qla2x00_alloc_fw_dump(ha);
  55. break;
  56. }
  57. return (count);
  58. }
  59. static struct bin_attribute sysfs_fw_dump_attr = {
  60. .attr = {
  61. .name = "fw_dump",
  62. .mode = S_IRUSR | S_IWUSR,
  63. .owner = THIS_MODULE,
  64. },
  65. .size = 0,
  66. .read = qla2x00_sysfs_read_fw_dump,
  67. .write = qla2x00_sysfs_write_fw_dump,
  68. };
  69. static ssize_t
  70. qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
  71. size_t count)
  72. {
  73. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  74. struct device, kobj)));
  75. unsigned long flags;
  76. if (!capable(CAP_SYS_ADMIN) || off != 0)
  77. return 0;
  78. /* Read NVRAM. */
  79. spin_lock_irqsave(&ha->hardware_lock, flags);
  80. ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
  81. ha->nvram_size);
  82. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  83. return ha->nvram_size;
  84. }
  85. static ssize_t
  86. qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
  87. size_t count)
  88. {
  89. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  90. struct device, kobj)));
  91. unsigned long flags;
  92. uint16_t cnt;
  93. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
  94. return 0;
  95. /* Checksum NVRAM. */
  96. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  97. uint32_t *iter;
  98. uint32_t chksum;
  99. iter = (uint32_t *)buf;
  100. chksum = 0;
  101. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  102. chksum += le32_to_cpu(*iter++);
  103. chksum = ~chksum + 1;
  104. *iter = cpu_to_le32(chksum);
  105. } else {
  106. uint8_t *iter;
  107. uint8_t chksum;
  108. iter = (uint8_t *)buf;
  109. chksum = 0;
  110. for (cnt = 0; cnt < count - 1; cnt++)
  111. chksum += *iter++;
  112. chksum = ~chksum + 1;
  113. *iter = chksum;
  114. }
  115. /* Write NVRAM. */
  116. spin_lock_irqsave(&ha->hardware_lock, flags);
  117. ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
  118. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  119. return (count);
  120. }
  121. static struct bin_attribute sysfs_nvram_attr = {
  122. .attr = {
  123. .name = "nvram",
  124. .mode = S_IRUSR | S_IWUSR,
  125. .owner = THIS_MODULE,
  126. },
  127. .size = 512,
  128. .read = qla2x00_sysfs_read_nvram,
  129. .write = qla2x00_sysfs_write_nvram,
  130. };
  131. static ssize_t
  132. qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off,
  133. size_t count)
  134. {
  135. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  136. struct device, kobj)));
  137. if (ha->optrom_state != QLA_SREADING)
  138. return 0;
  139. if (off > ha->optrom_size)
  140. return 0;
  141. if (off + count > ha->optrom_size)
  142. count = ha->optrom_size - off;
  143. memcpy(buf, &ha->optrom_buffer[off], count);
  144. return count;
  145. }
  146. static ssize_t
  147. qla2x00_sysfs_write_optrom(struct kobject *kobj, char *buf, loff_t off,
  148. size_t count)
  149. {
  150. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  151. struct device, kobj)));
  152. if (ha->optrom_state != QLA_SWRITING)
  153. return -EINVAL;
  154. if (off > ha->optrom_size)
  155. return -ERANGE;
  156. if (off + count > ha->optrom_size)
  157. count = ha->optrom_size - off;
  158. memcpy(&ha->optrom_buffer[off], buf, count);
  159. return count;
  160. }
  161. static struct bin_attribute sysfs_optrom_attr = {
  162. .attr = {
  163. .name = "optrom",
  164. .mode = S_IRUSR | S_IWUSR,
  165. .owner = THIS_MODULE,
  166. },
  167. .size = OPTROM_SIZE_24XX,
  168. .read = qla2x00_sysfs_read_optrom,
  169. .write = qla2x00_sysfs_write_optrom,
  170. };
  171. static ssize_t
  172. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off,
  173. size_t count)
  174. {
  175. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  176. struct device, kobj)));
  177. int val;
  178. if (off)
  179. return 0;
  180. if (sscanf(buf, "%d", &val) != 1)
  181. return -EINVAL;
  182. switch (val) {
  183. case 0:
  184. if (ha->optrom_state != QLA_SREADING &&
  185. ha->optrom_state != QLA_SWRITING)
  186. break;
  187. ha->optrom_state = QLA_SWAITING;
  188. vfree(ha->optrom_buffer);
  189. ha->optrom_buffer = NULL;
  190. break;
  191. case 1:
  192. if (ha->optrom_state != QLA_SWAITING)
  193. break;
  194. ha->optrom_state = QLA_SREADING;
  195. ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
  196. if (ha->optrom_buffer == NULL) {
  197. qla_printk(KERN_WARNING, ha,
  198. "Unable to allocate memory for optrom retrieval "
  199. "(%x).\n", ha->optrom_size);
  200. ha->optrom_state = QLA_SWAITING;
  201. return count;
  202. }
  203. memset(ha->optrom_buffer, 0, ha->optrom_size);
  204. ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0,
  205. ha->optrom_size);
  206. break;
  207. case 2:
  208. if (ha->optrom_state != QLA_SWAITING)
  209. break;
  210. ha->optrom_state = QLA_SWRITING;
  211. ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
  212. if (ha->optrom_buffer == NULL) {
  213. qla_printk(KERN_WARNING, ha,
  214. "Unable to allocate memory for optrom update "
  215. "(%x).\n", ha->optrom_size);
  216. ha->optrom_state = QLA_SWAITING;
  217. return count;
  218. }
  219. memset(ha->optrom_buffer, 0, ha->optrom_size);
  220. break;
  221. case 3:
  222. if (ha->optrom_state != QLA_SWRITING)
  223. break;
  224. ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0,
  225. ha->optrom_size);
  226. break;
  227. }
  228. return count;
  229. }
  230. static struct bin_attribute sysfs_optrom_ctl_attr = {
  231. .attr = {
  232. .name = "optrom_ctl",
  233. .mode = S_IWUSR,
  234. .owner = THIS_MODULE,
  235. },
  236. .size = 0,
  237. .write = qla2x00_sysfs_write_optrom_ctl,
  238. };
  239. static ssize_t
  240. qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off,
  241. size_t count)
  242. {
  243. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  244. struct device, kobj)));
  245. unsigned long flags;
  246. if (!capable(CAP_SYS_ADMIN) || off != 0)
  247. return 0;
  248. /* Read NVRAM. */
  249. spin_lock_irqsave(&ha->hardware_lock, flags);
  250. ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size);
  251. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  252. return ha->vpd_size;
  253. }
  254. static ssize_t
  255. qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off,
  256. size_t count)
  257. {
  258. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  259. struct device, kobj)));
  260. unsigned long flags;
  261. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
  262. return 0;
  263. /* Write NVRAM. */
  264. spin_lock_irqsave(&ha->hardware_lock, flags);
  265. ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
  266. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  267. return count;
  268. }
  269. static struct bin_attribute sysfs_vpd_attr = {
  270. .attr = {
  271. .name = "vpd",
  272. .mode = S_IRUSR | S_IWUSR,
  273. .owner = THIS_MODULE,
  274. },
  275. .size = 0,
  276. .read = qla2x00_sysfs_read_vpd,
  277. .write = qla2x00_sysfs_write_vpd,
  278. };
  279. static ssize_t
  280. qla2x00_sysfs_read_sfp(struct kobject *kobj, char *buf, loff_t off,
  281. size_t count)
  282. {
  283. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  284. struct device, kobj)));
  285. uint16_t iter, addr, offset;
  286. int rval;
  287. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  288. return 0;
  289. addr = 0xa0;
  290. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  291. iter++, offset += SFP_BLOCK_SIZE) {
  292. if (iter == 4) {
  293. /* Skip to next device address. */
  294. addr = 0xa2;
  295. offset = 0;
  296. }
  297. rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
  298. SFP_BLOCK_SIZE);
  299. if (rval != QLA_SUCCESS) {
  300. qla_printk(KERN_WARNING, ha,
  301. "Unable to read SFP data (%x/%x/%x).\n", rval,
  302. addr, offset);
  303. count = 0;
  304. break;
  305. }
  306. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  307. buf += SFP_BLOCK_SIZE;
  308. }
  309. return count;
  310. }
  311. static struct bin_attribute sysfs_sfp_attr = {
  312. .attr = {
  313. .name = "sfp",
  314. .mode = S_IRUSR | S_IWUSR,
  315. .owner = THIS_MODULE,
  316. },
  317. .size = SFP_DEV_SIZE * 2,
  318. .read = qla2x00_sysfs_read_sfp,
  319. };
  320. void
  321. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
  322. {
  323. struct Scsi_Host *host = ha->host;
  324. sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
  325. sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
  326. sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
  327. sysfs_create_bin_file(&host->shost_gendev.kobj,
  328. &sysfs_optrom_ctl_attr);
  329. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  330. sysfs_create_bin_file(&host->shost_gendev.kobj,
  331. &sysfs_vpd_attr);
  332. sysfs_create_bin_file(&host->shost_gendev.kobj,
  333. &sysfs_sfp_attr);
  334. }
  335. }
  336. void
  337. qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
  338. {
  339. struct Scsi_Host *host = ha->host;
  340. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
  341. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
  342. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
  343. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  344. &sysfs_optrom_ctl_attr);
  345. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  346. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  347. &sysfs_vpd_attr);
  348. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  349. &sysfs_sfp_attr);
  350. }
  351. if (ha->beacon_blink_led == 1)
  352. ha->isp_ops.beacon_off(ha);
  353. }
  354. /* Scsi_Host attributes. */
  355. static ssize_t
  356. qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
  357. {
  358. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  359. }
  360. static ssize_t
  361. qla2x00_fw_version_show(struct class_device *cdev, char *buf)
  362. {
  363. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  364. char fw_str[30];
  365. return snprintf(buf, PAGE_SIZE, "%s\n",
  366. ha->isp_ops.fw_version_str(ha, fw_str));
  367. }
  368. static ssize_t
  369. qla2x00_serial_num_show(struct class_device *cdev, char *buf)
  370. {
  371. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  372. uint32_t sn;
  373. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  374. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  375. sn % 100000);
  376. }
  377. static ssize_t
  378. qla2x00_isp_name_show(struct class_device *cdev, char *buf)
  379. {
  380. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  381. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  382. }
  383. static ssize_t
  384. qla2x00_isp_id_show(struct class_device *cdev, char *buf)
  385. {
  386. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  387. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  388. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  389. ha->product_id[3]);
  390. }
  391. static ssize_t
  392. qla2x00_model_name_show(struct class_device *cdev, char *buf)
  393. {
  394. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  395. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  396. }
  397. static ssize_t
  398. qla2x00_model_desc_show(struct class_device *cdev, char *buf)
  399. {
  400. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  401. return snprintf(buf, PAGE_SIZE, "%s\n",
  402. ha->model_desc ? ha->model_desc: "");
  403. }
  404. static ssize_t
  405. qla2x00_pci_info_show(struct class_device *cdev, char *buf)
  406. {
  407. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  408. char pci_info[30];
  409. return snprintf(buf, PAGE_SIZE, "%s\n",
  410. ha->isp_ops.pci_info_str(ha, pci_info));
  411. }
  412. static ssize_t
  413. qla2x00_state_show(struct class_device *cdev, char *buf)
  414. {
  415. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  416. int len = 0;
  417. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  418. atomic_read(&ha->loop_state) == LOOP_DEAD)
  419. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  420. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  421. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  422. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  423. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  424. else {
  425. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  426. switch (ha->current_topology) {
  427. case ISP_CFG_NL:
  428. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  429. break;
  430. case ISP_CFG_FL:
  431. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  432. break;
  433. case ISP_CFG_N:
  434. len += snprintf(buf + len, PAGE_SIZE-len,
  435. "N_Port to N_Port\n");
  436. break;
  437. case ISP_CFG_F:
  438. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  439. break;
  440. default:
  441. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  442. break;
  443. }
  444. }
  445. return len;
  446. }
  447. static ssize_t
  448. qla2x00_zio_show(struct class_device *cdev, char *buf)
  449. {
  450. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  451. int len = 0;
  452. switch (ha->zio_mode) {
  453. case QLA_ZIO_MODE_6:
  454. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  455. break;
  456. case QLA_ZIO_DISABLED:
  457. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  458. break;
  459. }
  460. return len;
  461. }
  462. static ssize_t
  463. qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
  464. {
  465. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  466. int val = 0;
  467. uint16_t zio_mode;
  468. if (!IS_ZIO_SUPPORTED(ha))
  469. return -ENOTSUPP;
  470. if (sscanf(buf, "%d", &val) != 1)
  471. return -EINVAL;
  472. if (val)
  473. zio_mode = QLA_ZIO_MODE_6;
  474. else
  475. zio_mode = QLA_ZIO_DISABLED;
  476. /* Update per-hba values and queue a reset. */
  477. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  478. ha->zio_mode = zio_mode;
  479. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  480. }
  481. return strlen(buf);
  482. }
  483. static ssize_t
  484. qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
  485. {
  486. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  487. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  488. }
  489. static ssize_t
  490. qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
  491. size_t count)
  492. {
  493. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  494. int val = 0;
  495. uint16_t zio_timer;
  496. if (sscanf(buf, "%d", &val) != 1)
  497. return -EINVAL;
  498. if (val > 25500 || val < 100)
  499. return -ERANGE;
  500. zio_timer = (uint16_t)(val / 100);
  501. ha->zio_timer = zio_timer;
  502. return strlen(buf);
  503. }
  504. static ssize_t
  505. qla2x00_beacon_show(struct class_device *cdev, char *buf)
  506. {
  507. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  508. int len = 0;
  509. if (ha->beacon_blink_led)
  510. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  511. else
  512. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  513. return len;
  514. }
  515. static ssize_t
  516. qla2x00_beacon_store(struct class_device *cdev, const char *buf,
  517. size_t count)
  518. {
  519. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  520. int val = 0;
  521. int rval;
  522. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  523. return -EPERM;
  524. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  525. qla_printk(KERN_WARNING, ha,
  526. "Abort ISP active -- ignoring beacon request.\n");
  527. return -EBUSY;
  528. }
  529. if (sscanf(buf, "%d", &val) != 1)
  530. return -EINVAL;
  531. if (val)
  532. rval = ha->isp_ops.beacon_on(ha);
  533. else
  534. rval = ha->isp_ops.beacon_off(ha);
  535. if (rval != QLA_SUCCESS)
  536. count = 0;
  537. return count;
  538. }
  539. static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
  540. NULL);
  541. static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  542. static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  543. static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  544. static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  545. static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  546. static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  547. static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  548. static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
  549. static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
  550. qla2x00_zio_store);
  551. static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  552. qla2x00_zio_timer_store);
  553. static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  554. qla2x00_beacon_store);
  555. struct class_device_attribute *qla2x00_host_attrs[] = {
  556. &class_device_attr_driver_version,
  557. &class_device_attr_fw_version,
  558. &class_device_attr_serial_num,
  559. &class_device_attr_isp_name,
  560. &class_device_attr_isp_id,
  561. &class_device_attr_model_name,
  562. &class_device_attr_model_desc,
  563. &class_device_attr_pci_info,
  564. &class_device_attr_state,
  565. &class_device_attr_zio,
  566. &class_device_attr_zio_timer,
  567. &class_device_attr_beacon,
  568. NULL,
  569. };
  570. /* Host attributes. */
  571. static void
  572. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  573. {
  574. scsi_qla_host_t *ha = to_qla_host(shost);
  575. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  576. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  577. }
  578. static void
  579. qla2x00_get_host_speed(struct Scsi_Host *shost)
  580. {
  581. scsi_qla_host_t *ha = to_qla_host(shost);
  582. uint32_t speed = 0;
  583. switch (ha->link_data_rate) {
  584. case PORT_SPEED_1GB:
  585. speed = 1;
  586. break;
  587. case PORT_SPEED_2GB:
  588. speed = 2;
  589. break;
  590. case PORT_SPEED_4GB:
  591. speed = 4;
  592. break;
  593. }
  594. fc_host_speed(shost) = speed;
  595. }
  596. static void
  597. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  598. {
  599. scsi_qla_host_t *ha = to_qla_host(shost);
  600. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  601. switch (ha->current_topology) {
  602. case ISP_CFG_NL:
  603. port_type = FC_PORTTYPE_LPORT;
  604. break;
  605. case ISP_CFG_FL:
  606. port_type = FC_PORTTYPE_NLPORT;
  607. break;
  608. case ISP_CFG_N:
  609. port_type = FC_PORTTYPE_PTP;
  610. break;
  611. case ISP_CFG_F:
  612. port_type = FC_PORTTYPE_NPORT;
  613. break;
  614. }
  615. fc_host_port_type(shost) = port_type;
  616. }
  617. static void
  618. qla2x00_get_starget_node_name(struct scsi_target *starget)
  619. {
  620. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  621. scsi_qla_host_t *ha = to_qla_host(host);
  622. fc_port_t *fcport;
  623. u64 node_name = 0;
  624. list_for_each_entry(fcport, &ha->fcports, list) {
  625. if (starget->id == fcport->os_target_id) {
  626. node_name = wwn_to_u64(fcport->node_name);
  627. break;
  628. }
  629. }
  630. fc_starget_node_name(starget) = node_name;
  631. }
  632. static void
  633. qla2x00_get_starget_port_name(struct scsi_target *starget)
  634. {
  635. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  636. scsi_qla_host_t *ha = to_qla_host(host);
  637. fc_port_t *fcport;
  638. u64 port_name = 0;
  639. list_for_each_entry(fcport, &ha->fcports, list) {
  640. if (starget->id == fcport->os_target_id) {
  641. port_name = wwn_to_u64(fcport->port_name);
  642. break;
  643. }
  644. }
  645. fc_starget_port_name(starget) = port_name;
  646. }
  647. static void
  648. qla2x00_get_starget_port_id(struct scsi_target *starget)
  649. {
  650. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  651. scsi_qla_host_t *ha = to_qla_host(host);
  652. fc_port_t *fcport;
  653. uint32_t port_id = ~0U;
  654. list_for_each_entry(fcport, &ha->fcports, list) {
  655. if (starget->id == fcport->os_target_id) {
  656. port_id = fcport->d_id.b.domain << 16 |
  657. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  658. break;
  659. }
  660. }
  661. fc_starget_port_id(starget) = port_id;
  662. }
  663. static void
  664. qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
  665. {
  666. struct Scsi_Host *host = rport_to_shost(rport);
  667. scsi_qla_host_t *ha = to_qla_host(host);
  668. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  669. }
  670. static void
  671. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  672. {
  673. struct Scsi_Host *host = rport_to_shost(rport);
  674. scsi_qla_host_t *ha = to_qla_host(host);
  675. if (timeout)
  676. ha->port_down_retry_count = timeout;
  677. else
  678. ha->port_down_retry_count = 1;
  679. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  680. }
  681. static int
  682. qla2x00_issue_lip(struct Scsi_Host *shost)
  683. {
  684. scsi_qla_host_t *ha = to_qla_host(shost);
  685. set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
  686. return 0;
  687. }
  688. static struct fc_host_statistics *
  689. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  690. {
  691. scsi_qla_host_t *ha = to_qla_host(shost);
  692. int rval;
  693. uint16_t mb_stat[1];
  694. link_stat_t stat_buf;
  695. struct fc_host_statistics *pfc_host_stat;
  696. pfc_host_stat = &ha->fc_host_stat;
  697. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  698. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  699. rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
  700. sizeof(stat_buf) / 4, mb_stat);
  701. } else {
  702. rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
  703. mb_stat);
  704. }
  705. if (rval != 0) {
  706. qla_printk(KERN_WARNING, ha,
  707. "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
  708. return pfc_host_stat;
  709. }
  710. pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
  711. pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
  712. pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
  713. pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
  714. pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
  715. pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
  716. return pfc_host_stat;
  717. }
  718. static void
  719. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  720. {
  721. scsi_qla_host_t *ha = to_qla_host(shost);
  722. qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
  723. }
  724. static void
  725. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  726. {
  727. scsi_qla_host_t *ha = to_qla_host(shost);
  728. set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
  729. }
  730. static void
  731. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  732. {
  733. scsi_qla_host_t *ha = to_qla_host(shost);
  734. u64 node_name;
  735. if (ha->device_flags & SWITCH_FOUND)
  736. node_name = wwn_to_u64(ha->fabric_node_name);
  737. else
  738. node_name = wwn_to_u64(ha->node_name);
  739. fc_host_fabric_name(shost) = node_name;
  740. }
  741. static void
  742. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  743. {
  744. scsi_qla_host_t *ha = to_qla_host(shost);
  745. if (!ha->flags.online)
  746. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  747. else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
  748. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  749. else
  750. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  751. }
  752. struct fc_function_template qla2xxx_transport_functions = {
  753. .show_host_node_name = 1,
  754. .show_host_port_name = 1,
  755. .show_host_supported_classes = 1,
  756. .get_host_port_id = qla2x00_get_host_port_id,
  757. .show_host_port_id = 1,
  758. .get_host_speed = qla2x00_get_host_speed,
  759. .show_host_speed = 1,
  760. .get_host_port_type = qla2x00_get_host_port_type,
  761. .show_host_port_type = 1,
  762. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  763. .show_host_symbolic_name = 1,
  764. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  765. .show_host_system_hostname = 1,
  766. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  767. .show_host_fabric_name = 1,
  768. .get_host_port_state = qla2x00_get_host_port_state,
  769. .show_host_port_state = 1,
  770. .dd_fcrport_size = sizeof(struct fc_port *),
  771. .show_rport_supported_classes = 1,
  772. .get_starget_node_name = qla2x00_get_starget_node_name,
  773. .show_starget_node_name = 1,
  774. .get_starget_port_name = qla2x00_get_starget_port_name,
  775. .show_starget_port_name = 1,
  776. .get_starget_port_id = qla2x00_get_starget_port_id,
  777. .show_starget_port_id = 1,
  778. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  779. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  780. .show_rport_dev_loss_tmo = 1,
  781. .issue_fc_host_lip = qla2x00_issue_lip,
  782. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  783. };
  784. void
  785. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  786. {
  787. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  788. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  789. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  790. }