qla_attr.c 29 KB

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