qla_attr.c 29 KB

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