qla_attr.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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. static struct sysfs_entry {
  321. char *name;
  322. struct bin_attribute *attr;
  323. int is4GBp_only;
  324. } bin_file_entries[] = {
  325. { "fw_dump", &sysfs_fw_dump_attr, },
  326. { "nvram", &sysfs_nvram_attr, },
  327. { "optrom", &sysfs_optrom_attr, },
  328. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  329. { "vpd", &sysfs_vpd_attr, 1 },
  330. { "sfp", &sysfs_sfp_attr, 1 },
  331. { NULL },
  332. };
  333. void
  334. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
  335. {
  336. struct Scsi_Host *host = ha->host;
  337. struct sysfs_entry *iter;
  338. int ret;
  339. for (iter = bin_file_entries; iter->name; iter++) {
  340. if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)))
  341. continue;
  342. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  343. iter->attr);
  344. if (ret)
  345. qla_printk(KERN_INFO, ha,
  346. "Unable to create sysfs %s binary attribute "
  347. "(%d).\n", iter->name, ret);
  348. }
  349. }
  350. void
  351. qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
  352. {
  353. struct Scsi_Host *host = ha->host;
  354. struct sysfs_entry *iter;
  355. for (iter = bin_file_entries; iter->name; iter++) {
  356. if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)))
  357. continue;
  358. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  359. iter->attr);
  360. }
  361. if (ha->beacon_blink_led == 1)
  362. ha->isp_ops.beacon_off(ha);
  363. }
  364. /* Scsi_Host attributes. */
  365. static ssize_t
  366. qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
  367. {
  368. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  369. }
  370. static ssize_t
  371. qla2x00_fw_version_show(struct class_device *cdev, char *buf)
  372. {
  373. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  374. char fw_str[30];
  375. return snprintf(buf, PAGE_SIZE, "%s\n",
  376. ha->isp_ops.fw_version_str(ha, fw_str));
  377. }
  378. static ssize_t
  379. qla2x00_serial_num_show(struct class_device *cdev, char *buf)
  380. {
  381. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  382. uint32_t sn;
  383. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  384. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  385. sn % 100000);
  386. }
  387. static ssize_t
  388. qla2x00_isp_name_show(struct class_device *cdev, char *buf)
  389. {
  390. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  391. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  392. }
  393. static ssize_t
  394. qla2x00_isp_id_show(struct class_device *cdev, char *buf)
  395. {
  396. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  397. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  398. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  399. ha->product_id[3]);
  400. }
  401. static ssize_t
  402. qla2x00_model_name_show(struct class_device *cdev, char *buf)
  403. {
  404. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  405. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  406. }
  407. static ssize_t
  408. qla2x00_model_desc_show(struct class_device *cdev, char *buf)
  409. {
  410. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  411. return snprintf(buf, PAGE_SIZE, "%s\n",
  412. ha->model_desc ? ha->model_desc: "");
  413. }
  414. static ssize_t
  415. qla2x00_pci_info_show(struct class_device *cdev, char *buf)
  416. {
  417. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  418. char pci_info[30];
  419. return snprintf(buf, PAGE_SIZE, "%s\n",
  420. ha->isp_ops.pci_info_str(ha, pci_info));
  421. }
  422. static ssize_t
  423. qla2x00_state_show(struct class_device *cdev, char *buf)
  424. {
  425. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  426. int len = 0;
  427. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  428. atomic_read(&ha->loop_state) == LOOP_DEAD)
  429. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  430. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  431. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  432. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  433. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  434. else {
  435. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  436. switch (ha->current_topology) {
  437. case ISP_CFG_NL:
  438. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  439. break;
  440. case ISP_CFG_FL:
  441. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  442. break;
  443. case ISP_CFG_N:
  444. len += snprintf(buf + len, PAGE_SIZE-len,
  445. "N_Port to N_Port\n");
  446. break;
  447. case ISP_CFG_F:
  448. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  449. break;
  450. default:
  451. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  452. break;
  453. }
  454. }
  455. return len;
  456. }
  457. static ssize_t
  458. qla2x00_zio_show(struct class_device *cdev, char *buf)
  459. {
  460. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  461. int len = 0;
  462. switch (ha->zio_mode) {
  463. case QLA_ZIO_MODE_6:
  464. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  465. break;
  466. case QLA_ZIO_DISABLED:
  467. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  468. break;
  469. }
  470. return len;
  471. }
  472. static ssize_t
  473. qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
  474. {
  475. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  476. int val = 0;
  477. uint16_t zio_mode;
  478. if (!IS_ZIO_SUPPORTED(ha))
  479. return -ENOTSUPP;
  480. if (sscanf(buf, "%d", &val) != 1)
  481. return -EINVAL;
  482. if (val)
  483. zio_mode = QLA_ZIO_MODE_6;
  484. else
  485. zio_mode = QLA_ZIO_DISABLED;
  486. /* Update per-hba values and queue a reset. */
  487. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  488. ha->zio_mode = zio_mode;
  489. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  490. }
  491. return strlen(buf);
  492. }
  493. static ssize_t
  494. qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
  495. {
  496. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  497. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  498. }
  499. static ssize_t
  500. qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
  501. size_t count)
  502. {
  503. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  504. int val = 0;
  505. uint16_t zio_timer;
  506. if (sscanf(buf, "%d", &val) != 1)
  507. return -EINVAL;
  508. if (val > 25500 || val < 100)
  509. return -ERANGE;
  510. zio_timer = (uint16_t)(val / 100);
  511. ha->zio_timer = zio_timer;
  512. return strlen(buf);
  513. }
  514. static ssize_t
  515. qla2x00_beacon_show(struct class_device *cdev, char *buf)
  516. {
  517. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  518. int len = 0;
  519. if (ha->beacon_blink_led)
  520. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  521. else
  522. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  523. return len;
  524. }
  525. static ssize_t
  526. qla2x00_beacon_store(struct class_device *cdev, const char *buf,
  527. size_t count)
  528. {
  529. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  530. int val = 0;
  531. int rval;
  532. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  533. return -EPERM;
  534. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  535. qla_printk(KERN_WARNING, ha,
  536. "Abort ISP active -- ignoring beacon request.\n");
  537. return -EBUSY;
  538. }
  539. if (sscanf(buf, "%d", &val) != 1)
  540. return -EINVAL;
  541. if (val)
  542. rval = ha->isp_ops.beacon_on(ha);
  543. else
  544. rval = ha->isp_ops.beacon_off(ha);
  545. if (rval != QLA_SUCCESS)
  546. count = 0;
  547. return count;
  548. }
  549. static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
  550. NULL);
  551. static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  552. static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  553. static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  554. static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  555. static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  556. static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  557. static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  558. static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
  559. static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
  560. qla2x00_zio_store);
  561. static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  562. qla2x00_zio_timer_store);
  563. static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  564. qla2x00_beacon_store);
  565. struct class_device_attribute *qla2x00_host_attrs[] = {
  566. &class_device_attr_driver_version,
  567. &class_device_attr_fw_version,
  568. &class_device_attr_serial_num,
  569. &class_device_attr_isp_name,
  570. &class_device_attr_isp_id,
  571. &class_device_attr_model_name,
  572. &class_device_attr_model_desc,
  573. &class_device_attr_pci_info,
  574. &class_device_attr_state,
  575. &class_device_attr_zio,
  576. &class_device_attr_zio_timer,
  577. &class_device_attr_beacon,
  578. NULL,
  579. };
  580. /* Host attributes. */
  581. static void
  582. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  583. {
  584. scsi_qla_host_t *ha = to_qla_host(shost);
  585. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  586. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  587. }
  588. static void
  589. qla2x00_get_host_speed(struct Scsi_Host *shost)
  590. {
  591. scsi_qla_host_t *ha = to_qla_host(shost);
  592. uint32_t speed = 0;
  593. switch (ha->link_data_rate) {
  594. case PORT_SPEED_1GB:
  595. speed = 1;
  596. break;
  597. case PORT_SPEED_2GB:
  598. speed = 2;
  599. break;
  600. case PORT_SPEED_4GB:
  601. speed = 4;
  602. break;
  603. }
  604. fc_host_speed(shost) = speed;
  605. }
  606. static void
  607. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  608. {
  609. scsi_qla_host_t *ha = to_qla_host(shost);
  610. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  611. switch (ha->current_topology) {
  612. case ISP_CFG_NL:
  613. port_type = FC_PORTTYPE_LPORT;
  614. break;
  615. case ISP_CFG_FL:
  616. port_type = FC_PORTTYPE_NLPORT;
  617. break;
  618. case ISP_CFG_N:
  619. port_type = FC_PORTTYPE_PTP;
  620. break;
  621. case ISP_CFG_F:
  622. port_type = FC_PORTTYPE_NPORT;
  623. break;
  624. }
  625. fc_host_port_type(shost) = port_type;
  626. }
  627. static void
  628. qla2x00_get_starget_node_name(struct scsi_target *starget)
  629. {
  630. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  631. scsi_qla_host_t *ha = to_qla_host(host);
  632. fc_port_t *fcport;
  633. u64 node_name = 0;
  634. list_for_each_entry(fcport, &ha->fcports, list) {
  635. if (starget->id == fcport->os_target_id) {
  636. node_name = wwn_to_u64(fcport->node_name);
  637. break;
  638. }
  639. }
  640. fc_starget_node_name(starget) = node_name;
  641. }
  642. static void
  643. qla2x00_get_starget_port_name(struct scsi_target *starget)
  644. {
  645. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  646. scsi_qla_host_t *ha = to_qla_host(host);
  647. fc_port_t *fcport;
  648. u64 port_name = 0;
  649. list_for_each_entry(fcport, &ha->fcports, list) {
  650. if (starget->id == fcport->os_target_id) {
  651. port_name = wwn_to_u64(fcport->port_name);
  652. break;
  653. }
  654. }
  655. fc_starget_port_name(starget) = port_name;
  656. }
  657. static void
  658. qla2x00_get_starget_port_id(struct scsi_target *starget)
  659. {
  660. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  661. scsi_qla_host_t *ha = to_qla_host(host);
  662. fc_port_t *fcport;
  663. uint32_t port_id = ~0U;
  664. list_for_each_entry(fcport, &ha->fcports, list) {
  665. if (starget->id == fcport->os_target_id) {
  666. port_id = fcport->d_id.b.domain << 16 |
  667. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  668. break;
  669. }
  670. }
  671. fc_starget_port_id(starget) = port_id;
  672. }
  673. static void
  674. qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
  675. {
  676. struct Scsi_Host *host = rport_to_shost(rport);
  677. scsi_qla_host_t *ha = to_qla_host(host);
  678. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  679. }
  680. static void
  681. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  682. {
  683. struct Scsi_Host *host = rport_to_shost(rport);
  684. scsi_qla_host_t *ha = to_qla_host(host);
  685. if (timeout)
  686. ha->port_down_retry_count = timeout;
  687. else
  688. ha->port_down_retry_count = 1;
  689. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  690. }
  691. static int
  692. qla2x00_issue_lip(struct Scsi_Host *shost)
  693. {
  694. scsi_qla_host_t *ha = to_qla_host(shost);
  695. set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
  696. return 0;
  697. }
  698. static struct fc_host_statistics *
  699. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  700. {
  701. scsi_qla_host_t *ha = to_qla_host(shost);
  702. int rval;
  703. uint16_t mb_stat[1];
  704. link_stat_t stat_buf;
  705. struct fc_host_statistics *pfc_host_stat;
  706. pfc_host_stat = &ha->fc_host_stat;
  707. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  708. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  709. rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
  710. sizeof(stat_buf) / 4, mb_stat);
  711. } else {
  712. rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
  713. mb_stat);
  714. }
  715. if (rval != 0) {
  716. qla_printk(KERN_WARNING, ha,
  717. "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
  718. return pfc_host_stat;
  719. }
  720. pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
  721. pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
  722. pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
  723. pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
  724. pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
  725. pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
  726. return pfc_host_stat;
  727. }
  728. static void
  729. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  730. {
  731. scsi_qla_host_t *ha = to_qla_host(shost);
  732. qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
  733. }
  734. static void
  735. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  736. {
  737. scsi_qla_host_t *ha = to_qla_host(shost);
  738. set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
  739. }
  740. static void
  741. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  742. {
  743. scsi_qla_host_t *ha = to_qla_host(shost);
  744. u64 node_name;
  745. if (ha->device_flags & SWITCH_FOUND)
  746. node_name = wwn_to_u64(ha->fabric_node_name);
  747. else
  748. node_name = wwn_to_u64(ha->node_name);
  749. fc_host_fabric_name(shost) = node_name;
  750. }
  751. static void
  752. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  753. {
  754. scsi_qla_host_t *ha = to_qla_host(shost);
  755. if (!ha->flags.online)
  756. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  757. else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
  758. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  759. else
  760. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  761. }
  762. struct fc_function_template qla2xxx_transport_functions = {
  763. .show_host_node_name = 1,
  764. .show_host_port_name = 1,
  765. .show_host_supported_classes = 1,
  766. .get_host_port_id = qla2x00_get_host_port_id,
  767. .show_host_port_id = 1,
  768. .get_host_speed = qla2x00_get_host_speed,
  769. .show_host_speed = 1,
  770. .get_host_port_type = qla2x00_get_host_port_type,
  771. .show_host_port_type = 1,
  772. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  773. .show_host_symbolic_name = 1,
  774. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  775. .show_host_system_hostname = 1,
  776. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  777. .show_host_fabric_name = 1,
  778. .get_host_port_state = qla2x00_get_host_port_state,
  779. .show_host_port_state = 1,
  780. .dd_fcrport_size = sizeof(struct fc_port *),
  781. .show_rport_supported_classes = 1,
  782. .get_starget_node_name = qla2x00_get_starget_node_name,
  783. .show_starget_node_name = 1,
  784. .get_starget_port_name = qla2x00_get_starget_port_name,
  785. .show_starget_port_name = 1,
  786. .get_starget_port_id = qla2x00_get_starget_port_id,
  787. .show_starget_port_id = 1,
  788. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  789. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  790. .show_rport_dev_loss_tmo = 1,
  791. .issue_fc_host_lip = qla2x00_issue_lip,
  792. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  793. };
  794. void
  795. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  796. {
  797. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  798. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  799. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  800. }