qla_attr.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 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. #include <linux/delay.h>
  11. static int qla24xx_vport_disable(struct fc_vport *, bool);
  12. /* SYSFS attributes --------------------------------------------------------- */
  13. static ssize_t
  14. qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
  15. struct bin_attribute *bin_attr,
  16. char *buf, loff_t off, size_t count)
  17. {
  18. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  19. struct device, kobj)));
  20. struct qla_hw_data *ha = vha->hw;
  21. if (ha->fw_dump_reading == 0)
  22. return 0;
  23. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  24. ha->fw_dump_len);
  25. }
  26. static ssize_t
  27. qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
  28. struct bin_attribute *bin_attr,
  29. char *buf, loff_t off, size_t count)
  30. {
  31. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  32. struct device, kobj)));
  33. struct qla_hw_data *ha = vha->hw;
  34. int reading;
  35. if (off != 0)
  36. return (0);
  37. reading = simple_strtol(buf, NULL, 10);
  38. switch (reading) {
  39. case 0:
  40. if (!ha->fw_dump_reading)
  41. break;
  42. qla_printk(KERN_INFO, ha,
  43. "Firmware dump cleared on (%ld).\n", vha->host_no);
  44. ha->fw_dump_reading = 0;
  45. ha->fw_dumped = 0;
  46. break;
  47. case 1:
  48. if (ha->fw_dumped && !ha->fw_dump_reading) {
  49. ha->fw_dump_reading = 1;
  50. qla_printk(KERN_INFO, ha,
  51. "Raw firmware dump ready for read on (%ld).\n",
  52. vha->host_no);
  53. }
  54. break;
  55. case 2:
  56. qla2x00_alloc_fw_dump(vha);
  57. break;
  58. case 3:
  59. qla2x00_system_error(vha);
  60. break;
  61. }
  62. return (count);
  63. }
  64. static struct bin_attribute sysfs_fw_dump_attr = {
  65. .attr = {
  66. .name = "fw_dump",
  67. .mode = S_IRUSR | S_IWUSR,
  68. },
  69. .size = 0,
  70. .read = qla2x00_sysfs_read_fw_dump,
  71. .write = qla2x00_sysfs_write_fw_dump,
  72. };
  73. static ssize_t
  74. qla2x00_sysfs_read_nvram(struct kobject *kobj,
  75. struct bin_attribute *bin_attr,
  76. char *buf, loff_t off, size_t count)
  77. {
  78. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  79. struct device, kobj)));
  80. struct qla_hw_data *ha = vha->hw;
  81. if (!capable(CAP_SYS_ADMIN))
  82. return 0;
  83. if (IS_NOCACHE_VPD_TYPE(ha))
  84. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_nvram << 2,
  85. ha->nvram_size);
  86. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  87. 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 *vha = shost_priv(dev_to_shost(container_of(kobj,
  95. struct device, kobj)));
  96. struct qla_hw_data *ha = vha->hw;
  97. uint16_t cnt;
  98. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  99. !ha->isp_ops->write_nvram)
  100. return 0;
  101. /* Checksum NVRAM. */
  102. if (IS_FWI2_CAPABLE(ha)) {
  103. uint32_t *iter;
  104. uint32_t chksum;
  105. iter = (uint32_t *)buf;
  106. chksum = 0;
  107. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  108. chksum += le32_to_cpu(*iter++);
  109. chksum = ~chksum + 1;
  110. *iter = cpu_to_le32(chksum);
  111. } else {
  112. uint8_t *iter;
  113. uint8_t chksum;
  114. iter = (uint8_t *)buf;
  115. chksum = 0;
  116. for (cnt = 0; cnt < count - 1; cnt++)
  117. chksum += *iter++;
  118. chksum = ~chksum + 1;
  119. *iter = chksum;
  120. }
  121. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  122. qla_printk(KERN_WARNING, ha,
  123. "HBA not online, failing NVRAM update.\n");
  124. return -EAGAIN;
  125. }
  126. /* Write NVRAM. */
  127. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  128. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  129. count);
  130. /* NVRAM settings take effect immediately. */
  131. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  132. qla2xxx_wake_dpc(vha);
  133. qla2x00_wait_for_chip_reset(vha);
  134. return (count);
  135. }
  136. static struct bin_attribute sysfs_nvram_attr = {
  137. .attr = {
  138. .name = "nvram",
  139. .mode = S_IRUSR | S_IWUSR,
  140. },
  141. .size = 512,
  142. .read = qla2x00_sysfs_read_nvram,
  143. .write = qla2x00_sysfs_write_nvram,
  144. };
  145. static ssize_t
  146. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  147. struct bin_attribute *bin_attr,
  148. char *buf, loff_t off, size_t count)
  149. {
  150. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  151. struct device, kobj)));
  152. struct qla_hw_data *ha = vha->hw;
  153. if (ha->optrom_state != QLA_SREADING)
  154. return 0;
  155. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  156. ha->optrom_region_size);
  157. }
  158. static ssize_t
  159. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  160. struct bin_attribute *bin_attr,
  161. char *buf, loff_t off, size_t count)
  162. {
  163. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  164. struct device, kobj)));
  165. struct qla_hw_data *ha = vha->hw;
  166. if (ha->optrom_state != QLA_SWRITING)
  167. return -EINVAL;
  168. if (off > ha->optrom_region_size)
  169. return -ERANGE;
  170. if (off + count > ha->optrom_region_size)
  171. count = ha->optrom_region_size - off;
  172. memcpy(&ha->optrom_buffer[off], buf, count);
  173. return count;
  174. }
  175. static struct bin_attribute sysfs_optrom_attr = {
  176. .attr = {
  177. .name = "optrom",
  178. .mode = S_IRUSR | S_IWUSR,
  179. },
  180. .size = 0,
  181. .read = qla2x00_sysfs_read_optrom,
  182. .write = qla2x00_sysfs_write_optrom,
  183. };
  184. static ssize_t
  185. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  186. struct bin_attribute *bin_attr,
  187. char *buf, loff_t off, size_t count)
  188. {
  189. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  190. struct device, kobj)));
  191. struct qla_hw_data *ha = vha->hw;
  192. uint32_t start = 0;
  193. uint32_t size = ha->optrom_size;
  194. int val, valid;
  195. if (off)
  196. return 0;
  197. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  198. return -EINVAL;
  199. if (start > ha->optrom_size)
  200. return -EINVAL;
  201. switch (val) {
  202. case 0:
  203. if (ha->optrom_state != QLA_SREADING &&
  204. ha->optrom_state != QLA_SWRITING)
  205. break;
  206. ha->optrom_state = QLA_SWAITING;
  207. DEBUG2(qla_printk(KERN_INFO, ha,
  208. "Freeing flash region allocation -- 0x%x bytes.\n",
  209. ha->optrom_region_size));
  210. vfree(ha->optrom_buffer);
  211. ha->optrom_buffer = NULL;
  212. break;
  213. case 1:
  214. if (ha->optrom_state != QLA_SWAITING)
  215. break;
  216. ha->optrom_region_start = start;
  217. ha->optrom_region_size = start + size > ha->optrom_size ?
  218. ha->optrom_size - start : size;
  219. ha->optrom_state = QLA_SREADING;
  220. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  221. if (ha->optrom_buffer == NULL) {
  222. qla_printk(KERN_WARNING, ha,
  223. "Unable to allocate memory for optrom retrieval "
  224. "(%x).\n", ha->optrom_region_size);
  225. ha->optrom_state = QLA_SWAITING;
  226. return count;
  227. }
  228. DEBUG2(qla_printk(KERN_INFO, ha,
  229. "Reading flash region -- 0x%x/0x%x.\n",
  230. ha->optrom_region_start, ha->optrom_region_size));
  231. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  232. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  233. ha->optrom_region_start, ha->optrom_region_size);
  234. break;
  235. case 2:
  236. if (ha->optrom_state != QLA_SWAITING)
  237. break;
  238. /*
  239. * We need to be more restrictive on which FLASH regions are
  240. * allowed to be updated via user-space. Regions accessible
  241. * via this method include:
  242. *
  243. * ISP21xx/ISP22xx/ISP23xx type boards:
  244. *
  245. * 0x000000 -> 0x020000 -- Boot code.
  246. *
  247. * ISP2322/ISP24xx type boards:
  248. *
  249. * 0x000000 -> 0x07ffff -- Boot code.
  250. * 0x080000 -> 0x0fffff -- Firmware.
  251. *
  252. * ISP25xx type boards:
  253. *
  254. * 0x000000 -> 0x07ffff -- Boot code.
  255. * 0x080000 -> 0x0fffff -- Firmware.
  256. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  257. */
  258. valid = 0;
  259. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  260. valid = 1;
  261. else if (start == (ha->flt_region_boot * 4) ||
  262. start == (ha->flt_region_fw * 4))
  263. valid = 1;
  264. else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
  265. valid = 1;
  266. if (!valid) {
  267. qla_printk(KERN_WARNING, ha,
  268. "Invalid start region 0x%x/0x%x.\n", start, size);
  269. return -EINVAL;
  270. }
  271. ha->optrom_region_start = start;
  272. ha->optrom_region_size = start + size > ha->optrom_size ?
  273. ha->optrom_size - start : size;
  274. ha->optrom_state = QLA_SWRITING;
  275. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  276. if (ha->optrom_buffer == NULL) {
  277. qla_printk(KERN_WARNING, ha,
  278. "Unable to allocate memory for optrom update "
  279. "(%x).\n", ha->optrom_region_size);
  280. ha->optrom_state = QLA_SWAITING;
  281. return count;
  282. }
  283. DEBUG2(qla_printk(KERN_INFO, ha,
  284. "Staging flash region write -- 0x%x/0x%x.\n",
  285. ha->optrom_region_start, ha->optrom_region_size));
  286. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  287. break;
  288. case 3:
  289. if (ha->optrom_state != QLA_SWRITING)
  290. break;
  291. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  292. qla_printk(KERN_WARNING, ha,
  293. "HBA not online, failing flash update.\n");
  294. return -EAGAIN;
  295. }
  296. DEBUG2(qla_printk(KERN_INFO, ha,
  297. "Writing flash region -- 0x%x/0x%x.\n",
  298. ha->optrom_region_start, ha->optrom_region_size));
  299. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  300. ha->optrom_region_start, ha->optrom_region_size);
  301. break;
  302. default:
  303. count = -EINVAL;
  304. }
  305. return count;
  306. }
  307. static struct bin_attribute sysfs_optrom_ctl_attr = {
  308. .attr = {
  309. .name = "optrom_ctl",
  310. .mode = S_IWUSR,
  311. },
  312. .size = 0,
  313. .write = qla2x00_sysfs_write_optrom_ctl,
  314. };
  315. static ssize_t
  316. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  317. struct bin_attribute *bin_attr,
  318. char *buf, loff_t off, size_t count)
  319. {
  320. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  321. struct device, kobj)));
  322. struct qla_hw_data *ha = vha->hw;
  323. if (!capable(CAP_SYS_ADMIN))
  324. return 0;
  325. if (IS_NOCACHE_VPD_TYPE(ha))
  326. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  327. ha->vpd_size);
  328. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  329. }
  330. static ssize_t
  331. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  332. struct bin_attribute *bin_attr,
  333. char *buf, loff_t off, size_t count)
  334. {
  335. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  336. struct device, kobj)));
  337. struct qla_hw_data *ha = vha->hw;
  338. uint8_t *tmp_data;
  339. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  340. !ha->isp_ops->write_nvram)
  341. return 0;
  342. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  343. qla_printk(KERN_WARNING, ha,
  344. "HBA not online, failing VPD update.\n");
  345. return -EAGAIN;
  346. }
  347. /* Write NVRAM. */
  348. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  349. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  350. /* Update flash version information for 4Gb & above. */
  351. if (!IS_FWI2_CAPABLE(ha))
  352. goto done;
  353. tmp_data = vmalloc(256);
  354. if (!tmp_data) {
  355. qla_printk(KERN_WARNING, ha,
  356. "Unable to allocate memory for VPD information update.\n");
  357. goto done;
  358. }
  359. ha->isp_ops->get_flash_version(vha, tmp_data);
  360. vfree(tmp_data);
  361. done:
  362. return count;
  363. }
  364. static struct bin_attribute sysfs_vpd_attr = {
  365. .attr = {
  366. .name = "vpd",
  367. .mode = S_IRUSR | S_IWUSR,
  368. },
  369. .size = 0,
  370. .read = qla2x00_sysfs_read_vpd,
  371. .write = qla2x00_sysfs_write_vpd,
  372. };
  373. static ssize_t
  374. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  375. struct bin_attribute *bin_attr,
  376. char *buf, loff_t off, size_t count)
  377. {
  378. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  379. struct device, kobj)));
  380. struct qla_hw_data *ha = vha->hw;
  381. uint16_t iter, addr, offset;
  382. int rval;
  383. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  384. return 0;
  385. if (ha->sfp_data)
  386. goto do_read;
  387. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  388. &ha->sfp_data_dma);
  389. if (!ha->sfp_data) {
  390. qla_printk(KERN_WARNING, ha,
  391. "Unable to allocate memory for SFP read-data.\n");
  392. return 0;
  393. }
  394. do_read:
  395. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  396. addr = 0xa0;
  397. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  398. iter++, offset += SFP_BLOCK_SIZE) {
  399. if (iter == 4) {
  400. /* Skip to next device address. */
  401. addr = 0xa2;
  402. offset = 0;
  403. }
  404. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  405. SFP_BLOCK_SIZE);
  406. if (rval != QLA_SUCCESS) {
  407. qla_printk(KERN_WARNING, ha,
  408. "Unable to read SFP data (%x/%x/%x).\n", rval,
  409. addr, offset);
  410. count = 0;
  411. break;
  412. }
  413. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  414. buf += SFP_BLOCK_SIZE;
  415. }
  416. return count;
  417. }
  418. static struct bin_attribute sysfs_sfp_attr = {
  419. .attr = {
  420. .name = "sfp",
  421. .mode = S_IRUSR | S_IWUSR,
  422. },
  423. .size = SFP_DEV_SIZE * 2,
  424. .read = qla2x00_sysfs_read_sfp,
  425. };
  426. static ssize_t
  427. qla2x00_sysfs_write_reset(struct kobject *kobj,
  428. struct bin_attribute *bin_attr,
  429. char *buf, loff_t off, size_t count)
  430. {
  431. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  432. struct device, kobj)));
  433. struct qla_hw_data *ha = vha->hw;
  434. int type;
  435. if (off != 0)
  436. return 0;
  437. type = simple_strtol(buf, NULL, 10);
  438. switch (type) {
  439. case 0x2025c:
  440. qla_printk(KERN_INFO, ha,
  441. "Issuing ISP reset on (%ld).\n", vha->host_no);
  442. scsi_block_requests(vha->host);
  443. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  444. qla2xxx_wake_dpc(vha);
  445. qla2x00_wait_for_chip_reset(vha);
  446. scsi_unblock_requests(vha->host);
  447. break;
  448. case 0x2025d:
  449. if (!IS_QLA81XX(ha))
  450. break;
  451. qla_printk(KERN_INFO, ha,
  452. "Issuing MPI reset on (%ld).\n", vha->host_no);
  453. /* Make sure FC side is not in reset */
  454. qla2x00_wait_for_hba_online(vha);
  455. /* Issue MPI reset */
  456. scsi_block_requests(vha->host);
  457. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  458. qla_printk(KERN_WARNING, ha,
  459. "MPI reset failed on (%ld).\n", vha->host_no);
  460. scsi_unblock_requests(vha->host);
  461. break;
  462. }
  463. return count;
  464. }
  465. static struct bin_attribute sysfs_reset_attr = {
  466. .attr = {
  467. .name = "reset",
  468. .mode = S_IWUSR,
  469. },
  470. .size = 0,
  471. .write = qla2x00_sysfs_write_reset,
  472. };
  473. static ssize_t
  474. qla2x00_sysfs_write_edc(struct kobject *kobj,
  475. struct bin_attribute *bin_attr,
  476. char *buf, loff_t off, size_t count)
  477. {
  478. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  479. struct device, kobj)));
  480. struct qla_hw_data *ha = vha->hw;
  481. uint16_t dev, adr, opt, len;
  482. int rval;
  483. ha->edc_data_len = 0;
  484. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  485. return 0;
  486. if (!ha->edc_data) {
  487. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  488. &ha->edc_data_dma);
  489. if (!ha->edc_data) {
  490. DEBUG2(qla_printk(KERN_INFO, ha,
  491. "Unable to allocate memory for EDC write.\n"));
  492. return 0;
  493. }
  494. }
  495. dev = le16_to_cpup((void *)&buf[0]);
  496. adr = le16_to_cpup((void *)&buf[2]);
  497. opt = le16_to_cpup((void *)&buf[4]);
  498. len = le16_to_cpup((void *)&buf[6]);
  499. if (!(opt & BIT_0))
  500. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  501. return -EINVAL;
  502. memcpy(ha->edc_data, &buf[8], len);
  503. rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
  504. ha->edc_data, len, opt);
  505. if (rval != QLA_SUCCESS) {
  506. DEBUG2(qla_printk(KERN_INFO, ha,
  507. "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
  508. rval, dev, adr, opt, len, *buf));
  509. return 0;
  510. }
  511. return count;
  512. }
  513. static struct bin_attribute sysfs_edc_attr = {
  514. .attr = {
  515. .name = "edc",
  516. .mode = S_IWUSR,
  517. },
  518. .size = 0,
  519. .write = qla2x00_sysfs_write_edc,
  520. };
  521. static ssize_t
  522. qla2x00_sysfs_write_edc_status(struct kobject *kobj,
  523. struct bin_attribute *bin_attr,
  524. char *buf, loff_t off, size_t count)
  525. {
  526. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  527. struct device, kobj)));
  528. struct qla_hw_data *ha = vha->hw;
  529. uint16_t dev, adr, opt, len;
  530. int rval;
  531. ha->edc_data_len = 0;
  532. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  533. return 0;
  534. if (!ha->edc_data) {
  535. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  536. &ha->edc_data_dma);
  537. if (!ha->edc_data) {
  538. DEBUG2(qla_printk(KERN_INFO, ha,
  539. "Unable to allocate memory for EDC status.\n"));
  540. return 0;
  541. }
  542. }
  543. dev = le16_to_cpup((void *)&buf[0]);
  544. adr = le16_to_cpup((void *)&buf[2]);
  545. opt = le16_to_cpup((void *)&buf[4]);
  546. len = le16_to_cpup((void *)&buf[6]);
  547. if (!(opt & BIT_0))
  548. if (len == 0 || len > DMA_POOL_SIZE)
  549. return -EINVAL;
  550. memset(ha->edc_data, 0, len);
  551. rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
  552. ha->edc_data, len, opt);
  553. if (rval != QLA_SUCCESS) {
  554. DEBUG2(qla_printk(KERN_INFO, ha,
  555. "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
  556. rval, dev, adr, opt, len));
  557. return 0;
  558. }
  559. ha->edc_data_len = len;
  560. return count;
  561. }
  562. static ssize_t
  563. qla2x00_sysfs_read_edc_status(struct kobject *kobj,
  564. struct bin_attribute *bin_attr,
  565. char *buf, loff_t off, size_t count)
  566. {
  567. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  568. struct device, kobj)));
  569. struct qla_hw_data *ha = vha->hw;
  570. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  571. return 0;
  572. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  573. return -EINVAL;
  574. memcpy(buf, ha->edc_data, ha->edc_data_len);
  575. return ha->edc_data_len;
  576. }
  577. static struct bin_attribute sysfs_edc_status_attr = {
  578. .attr = {
  579. .name = "edc_status",
  580. .mode = S_IRUSR | S_IWUSR,
  581. },
  582. .size = 0,
  583. .write = qla2x00_sysfs_write_edc_status,
  584. .read = qla2x00_sysfs_read_edc_status,
  585. };
  586. static struct sysfs_entry {
  587. char *name;
  588. struct bin_attribute *attr;
  589. int is4GBp_only;
  590. } bin_file_entries[] = {
  591. { "fw_dump", &sysfs_fw_dump_attr, },
  592. { "nvram", &sysfs_nvram_attr, },
  593. { "optrom", &sysfs_optrom_attr, },
  594. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  595. { "vpd", &sysfs_vpd_attr, 1 },
  596. { "sfp", &sysfs_sfp_attr, 1 },
  597. { "reset", &sysfs_reset_attr, },
  598. { "edc", &sysfs_edc_attr, 2 },
  599. { "edc_status", &sysfs_edc_status_attr, 2 },
  600. { NULL },
  601. };
  602. void
  603. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  604. {
  605. struct Scsi_Host *host = vha->host;
  606. struct sysfs_entry *iter;
  607. int ret;
  608. for (iter = bin_file_entries; iter->name; iter++) {
  609. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  610. continue;
  611. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  612. continue;
  613. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  614. iter->attr);
  615. if (ret)
  616. qla_printk(KERN_INFO, vha->hw,
  617. "Unable to create sysfs %s binary attribute "
  618. "(%d).\n", iter->name, ret);
  619. }
  620. }
  621. void
  622. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  623. {
  624. struct Scsi_Host *host = vha->host;
  625. struct sysfs_entry *iter;
  626. struct qla_hw_data *ha = vha->hw;
  627. for (iter = bin_file_entries; iter->name; iter++) {
  628. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  629. continue;
  630. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  631. continue;
  632. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  633. iter->attr);
  634. }
  635. if (ha->beacon_blink_led == 1)
  636. ha->isp_ops->beacon_off(vha);
  637. }
  638. /* Scsi_Host attributes. */
  639. static ssize_t
  640. qla2x00_drvr_version_show(struct device *dev,
  641. struct device_attribute *attr, char *buf)
  642. {
  643. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  644. }
  645. static ssize_t
  646. qla2x00_fw_version_show(struct device *dev,
  647. struct device_attribute *attr, char *buf)
  648. {
  649. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  650. struct qla_hw_data *ha = vha->hw;
  651. char fw_str[128];
  652. return snprintf(buf, PAGE_SIZE, "%s\n",
  653. ha->isp_ops->fw_version_str(vha, fw_str));
  654. }
  655. static ssize_t
  656. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  657. char *buf)
  658. {
  659. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  660. struct qla_hw_data *ha = vha->hw;
  661. uint32_t sn;
  662. if (IS_FWI2_CAPABLE(ha)) {
  663. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  664. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  665. }
  666. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  667. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  668. sn % 100000);
  669. }
  670. static ssize_t
  671. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  672. char *buf)
  673. {
  674. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  675. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  676. }
  677. static ssize_t
  678. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  679. char *buf)
  680. {
  681. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  682. struct qla_hw_data *ha = vha->hw;
  683. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  684. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  685. ha->product_id[3]);
  686. }
  687. static ssize_t
  688. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  689. char *buf)
  690. {
  691. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  692. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  693. }
  694. static ssize_t
  695. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  696. char *buf)
  697. {
  698. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  699. return snprintf(buf, PAGE_SIZE, "%s\n",
  700. vha->hw->model_desc ? vha->hw->model_desc : "");
  701. }
  702. static ssize_t
  703. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  704. char *buf)
  705. {
  706. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  707. char pci_info[30];
  708. return snprintf(buf, PAGE_SIZE, "%s\n",
  709. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  710. }
  711. static ssize_t
  712. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  713. char *buf)
  714. {
  715. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  716. struct qla_hw_data *ha = vha->hw;
  717. int len = 0;
  718. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  719. atomic_read(&vha->loop_state) == LOOP_DEAD)
  720. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  721. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  722. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  723. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  724. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  725. else {
  726. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  727. switch (ha->current_topology) {
  728. case ISP_CFG_NL:
  729. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  730. break;
  731. case ISP_CFG_FL:
  732. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  733. break;
  734. case ISP_CFG_N:
  735. len += snprintf(buf + len, PAGE_SIZE-len,
  736. "N_Port to N_Port\n");
  737. break;
  738. case ISP_CFG_F:
  739. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  740. break;
  741. default:
  742. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  743. break;
  744. }
  745. }
  746. return len;
  747. }
  748. static ssize_t
  749. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  750. char *buf)
  751. {
  752. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  753. int len = 0;
  754. switch (vha->hw->zio_mode) {
  755. case QLA_ZIO_MODE_6:
  756. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  757. break;
  758. case QLA_ZIO_DISABLED:
  759. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  760. break;
  761. }
  762. return len;
  763. }
  764. static ssize_t
  765. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  766. const char *buf, size_t count)
  767. {
  768. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  769. struct qla_hw_data *ha = vha->hw;
  770. int val = 0;
  771. uint16_t zio_mode;
  772. if (!IS_ZIO_SUPPORTED(ha))
  773. return -ENOTSUPP;
  774. if (sscanf(buf, "%d", &val) != 1)
  775. return -EINVAL;
  776. if (val)
  777. zio_mode = QLA_ZIO_MODE_6;
  778. else
  779. zio_mode = QLA_ZIO_DISABLED;
  780. /* Update per-hba values and queue a reset. */
  781. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  782. ha->zio_mode = zio_mode;
  783. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  784. }
  785. return strlen(buf);
  786. }
  787. static ssize_t
  788. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  789. char *buf)
  790. {
  791. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  792. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  793. }
  794. static ssize_t
  795. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  796. const char *buf, size_t count)
  797. {
  798. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  799. int val = 0;
  800. uint16_t zio_timer;
  801. if (sscanf(buf, "%d", &val) != 1)
  802. return -EINVAL;
  803. if (val > 25500 || val < 100)
  804. return -ERANGE;
  805. zio_timer = (uint16_t)(val / 100);
  806. vha->hw->zio_timer = zio_timer;
  807. return strlen(buf);
  808. }
  809. static ssize_t
  810. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  811. char *buf)
  812. {
  813. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  814. int len = 0;
  815. if (vha->hw->beacon_blink_led)
  816. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  817. else
  818. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  819. return len;
  820. }
  821. static ssize_t
  822. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  823. const char *buf, size_t count)
  824. {
  825. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  826. struct qla_hw_data *ha = vha->hw;
  827. int val = 0;
  828. int rval;
  829. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  830. return -EPERM;
  831. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  832. qla_printk(KERN_WARNING, ha,
  833. "Abort ISP active -- ignoring beacon request.\n");
  834. return -EBUSY;
  835. }
  836. if (sscanf(buf, "%d", &val) != 1)
  837. return -EINVAL;
  838. if (val)
  839. rval = ha->isp_ops->beacon_on(vha);
  840. else
  841. rval = ha->isp_ops->beacon_off(vha);
  842. if (rval != QLA_SUCCESS)
  843. count = 0;
  844. return count;
  845. }
  846. static ssize_t
  847. qla2x00_optrom_bios_version_show(struct device *dev,
  848. struct device_attribute *attr, char *buf)
  849. {
  850. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  851. struct qla_hw_data *ha = vha->hw;
  852. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  853. ha->bios_revision[0]);
  854. }
  855. static ssize_t
  856. qla2x00_optrom_efi_version_show(struct device *dev,
  857. struct device_attribute *attr, char *buf)
  858. {
  859. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  860. struct qla_hw_data *ha = vha->hw;
  861. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  862. ha->efi_revision[0]);
  863. }
  864. static ssize_t
  865. qla2x00_optrom_fcode_version_show(struct device *dev,
  866. struct device_attribute *attr, char *buf)
  867. {
  868. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  869. struct qla_hw_data *ha = vha->hw;
  870. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  871. ha->fcode_revision[0]);
  872. }
  873. static ssize_t
  874. qla2x00_optrom_fw_version_show(struct device *dev,
  875. struct device_attribute *attr, char *buf)
  876. {
  877. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  878. struct qla_hw_data *ha = vha->hw;
  879. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  880. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  881. ha->fw_revision[3]);
  882. }
  883. static ssize_t
  884. qla2x00_total_isp_aborts_show(struct device *dev,
  885. struct device_attribute *attr, char *buf)
  886. {
  887. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  888. struct qla_hw_data *ha = vha->hw;
  889. return snprintf(buf, PAGE_SIZE, "%d\n",
  890. ha->qla_stats.total_isp_aborts);
  891. }
  892. static ssize_t
  893. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  894. char *buf)
  895. {
  896. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  897. struct qla_hw_data *ha = vha->hw;
  898. if (!IS_QLA81XX(ha))
  899. return snprintf(buf, PAGE_SIZE, "\n");
  900. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  901. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  902. ha->mpi_capabilities);
  903. }
  904. static ssize_t
  905. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  906. char *buf)
  907. {
  908. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  909. struct qla_hw_data *ha = vha->hw;
  910. if (!IS_QLA81XX(ha))
  911. return snprintf(buf, PAGE_SIZE, "\n");
  912. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  913. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  914. }
  915. static ssize_t
  916. qla2x00_flash_block_size_show(struct device *dev,
  917. struct device_attribute *attr, char *buf)
  918. {
  919. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  920. struct qla_hw_data *ha = vha->hw;
  921. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  922. }
  923. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  924. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  925. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  926. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  927. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  928. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  929. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  930. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  931. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  932. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  933. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  934. qla2x00_zio_timer_store);
  935. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  936. qla2x00_beacon_store);
  937. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  938. qla2x00_optrom_bios_version_show, NULL);
  939. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  940. qla2x00_optrom_efi_version_show, NULL);
  941. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  942. qla2x00_optrom_fcode_version_show, NULL);
  943. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  944. NULL);
  945. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  946. NULL);
  947. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  948. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  949. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  950. NULL);
  951. struct device_attribute *qla2x00_host_attrs[] = {
  952. &dev_attr_driver_version,
  953. &dev_attr_fw_version,
  954. &dev_attr_serial_num,
  955. &dev_attr_isp_name,
  956. &dev_attr_isp_id,
  957. &dev_attr_model_name,
  958. &dev_attr_model_desc,
  959. &dev_attr_pci_info,
  960. &dev_attr_link_state,
  961. &dev_attr_zio,
  962. &dev_attr_zio_timer,
  963. &dev_attr_beacon,
  964. &dev_attr_optrom_bios_version,
  965. &dev_attr_optrom_efi_version,
  966. &dev_attr_optrom_fcode_version,
  967. &dev_attr_optrom_fw_version,
  968. &dev_attr_total_isp_aborts,
  969. &dev_attr_mpi_version,
  970. &dev_attr_phy_version,
  971. &dev_attr_flash_block_size,
  972. NULL,
  973. };
  974. /* Host attributes. */
  975. static void
  976. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  977. {
  978. scsi_qla_host_t *vha = shost_priv(shost);
  979. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  980. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  981. }
  982. static void
  983. qla2x00_get_host_speed(struct Scsi_Host *shost)
  984. {
  985. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  986. (shost_priv(shost)))->hw;
  987. u32 speed = FC_PORTSPEED_UNKNOWN;
  988. switch (ha->link_data_rate) {
  989. case PORT_SPEED_1GB:
  990. speed = FC_PORTSPEED_1GBIT;
  991. break;
  992. case PORT_SPEED_2GB:
  993. speed = FC_PORTSPEED_2GBIT;
  994. break;
  995. case PORT_SPEED_4GB:
  996. speed = FC_PORTSPEED_4GBIT;
  997. break;
  998. case PORT_SPEED_8GB:
  999. speed = FC_PORTSPEED_8GBIT;
  1000. break;
  1001. case PORT_SPEED_10GB:
  1002. speed = FC_PORTSPEED_10GBIT;
  1003. break;
  1004. }
  1005. fc_host_speed(shost) = speed;
  1006. }
  1007. static void
  1008. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1009. {
  1010. scsi_qla_host_t *vha = shost_priv(shost);
  1011. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1012. if (vha->vp_idx) {
  1013. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1014. return;
  1015. }
  1016. switch (vha->hw->current_topology) {
  1017. case ISP_CFG_NL:
  1018. port_type = FC_PORTTYPE_LPORT;
  1019. break;
  1020. case ISP_CFG_FL:
  1021. port_type = FC_PORTTYPE_NLPORT;
  1022. break;
  1023. case ISP_CFG_N:
  1024. port_type = FC_PORTTYPE_PTP;
  1025. break;
  1026. case ISP_CFG_F:
  1027. port_type = FC_PORTTYPE_NPORT;
  1028. break;
  1029. }
  1030. fc_host_port_type(shost) = port_type;
  1031. }
  1032. static void
  1033. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1034. {
  1035. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1036. scsi_qla_host_t *vha = shost_priv(host);
  1037. fc_port_t *fcport;
  1038. u64 node_name = 0;
  1039. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1040. if (fcport->rport &&
  1041. starget->id == fcport->rport->scsi_target_id) {
  1042. node_name = wwn_to_u64(fcport->node_name);
  1043. break;
  1044. }
  1045. }
  1046. fc_starget_node_name(starget) = node_name;
  1047. }
  1048. static void
  1049. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1050. {
  1051. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1052. scsi_qla_host_t *vha = shost_priv(host);
  1053. fc_port_t *fcport;
  1054. u64 port_name = 0;
  1055. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1056. if (fcport->rport &&
  1057. starget->id == fcport->rport->scsi_target_id) {
  1058. port_name = wwn_to_u64(fcport->port_name);
  1059. break;
  1060. }
  1061. }
  1062. fc_starget_port_name(starget) = port_name;
  1063. }
  1064. static void
  1065. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1066. {
  1067. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1068. scsi_qla_host_t *vha = shost_priv(host);
  1069. fc_port_t *fcport;
  1070. uint32_t port_id = ~0U;
  1071. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1072. if (fcport->rport &&
  1073. starget->id == fcport->rport->scsi_target_id) {
  1074. port_id = fcport->d_id.b.domain << 16 |
  1075. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1076. break;
  1077. }
  1078. }
  1079. fc_starget_port_id(starget) = port_id;
  1080. }
  1081. static void
  1082. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1083. {
  1084. if (timeout)
  1085. rport->dev_loss_tmo = timeout;
  1086. else
  1087. rport->dev_loss_tmo = 1;
  1088. }
  1089. static void
  1090. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1091. {
  1092. struct Scsi_Host *host = rport_to_shost(rport);
  1093. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1094. if (!fcport)
  1095. return;
  1096. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev)))
  1097. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1098. else
  1099. qla2x00_abort_fcport_cmds(fcport);
  1100. /*
  1101. * Transport has effectively 'deleted' the rport, clear
  1102. * all local references.
  1103. */
  1104. spin_lock_irq(host->host_lock);
  1105. fcport->rport = NULL;
  1106. *((fc_port_t **)rport->dd_data) = NULL;
  1107. spin_unlock_irq(host->host_lock);
  1108. }
  1109. static void
  1110. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1111. {
  1112. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1113. if (!fcport)
  1114. return;
  1115. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1116. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1117. return;
  1118. }
  1119. /*
  1120. * At this point all fcport's software-states are cleared. Perform any
  1121. * final cleanup of firmware resources (PCBs and XCBs).
  1122. */
  1123. if (fcport->loop_id != FC_NO_LOOP_ID)
  1124. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1125. fcport->loop_id, fcport->d_id.b.domain,
  1126. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1127. qla2x00_abort_fcport_cmds(fcport);
  1128. }
  1129. static int
  1130. qla2x00_issue_lip(struct Scsi_Host *shost)
  1131. {
  1132. scsi_qla_host_t *vha = shost_priv(shost);
  1133. qla2x00_loop_reset(vha);
  1134. return 0;
  1135. }
  1136. static struct fc_host_statistics *
  1137. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1138. {
  1139. scsi_qla_host_t *vha = shost_priv(shost);
  1140. struct qla_hw_data *ha = vha->hw;
  1141. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1142. int rval;
  1143. struct link_statistics *stats;
  1144. dma_addr_t stats_dma;
  1145. struct fc_host_statistics *pfc_host_stat;
  1146. pfc_host_stat = &ha->fc_host_stat;
  1147. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1148. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1149. if (stats == NULL) {
  1150. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1151. __func__, base_vha->host_no));
  1152. goto done;
  1153. }
  1154. memset(stats, 0, DMA_POOL_SIZE);
  1155. rval = QLA_FUNCTION_FAILED;
  1156. if (IS_FWI2_CAPABLE(ha)) {
  1157. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1158. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1159. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1160. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1161. !ha->dpc_active) {
  1162. /* Must be in a 'READY' state for statistics retrieval. */
  1163. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1164. stats, stats_dma);
  1165. }
  1166. if (rval != QLA_SUCCESS)
  1167. goto done_free;
  1168. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1169. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1170. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1171. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1172. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1173. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1174. if (IS_FWI2_CAPABLE(ha)) {
  1175. pfc_host_stat->lip_count = stats->lip_cnt;
  1176. pfc_host_stat->tx_frames = stats->tx_frames;
  1177. pfc_host_stat->rx_frames = stats->rx_frames;
  1178. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1179. pfc_host_stat->nos_count = stats->nos_rcvd;
  1180. }
  1181. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1182. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1183. done_free:
  1184. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1185. done:
  1186. return pfc_host_stat;
  1187. }
  1188. static void
  1189. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1190. {
  1191. scsi_qla_host_t *vha = shost_priv(shost);
  1192. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1193. }
  1194. static void
  1195. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1196. {
  1197. scsi_qla_host_t *vha = shost_priv(shost);
  1198. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1199. }
  1200. static void
  1201. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1202. {
  1203. scsi_qla_host_t *vha = shost_priv(shost);
  1204. u64 node_name;
  1205. if (vha->device_flags & SWITCH_FOUND)
  1206. node_name = wwn_to_u64(vha->fabric_node_name);
  1207. else
  1208. node_name = wwn_to_u64(vha->node_name);
  1209. fc_host_fabric_name(shost) = node_name;
  1210. }
  1211. static void
  1212. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1213. {
  1214. scsi_qla_host_t *vha = shost_priv(shost);
  1215. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1216. if (!base_vha->flags.online)
  1217. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1218. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1219. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1220. else
  1221. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1222. }
  1223. static int
  1224. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1225. {
  1226. int ret = 0;
  1227. int cnt = 0;
  1228. uint8_t qos = QLA_DEFAULT_QUE_QOS;
  1229. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1230. scsi_qla_host_t *vha = NULL;
  1231. struct qla_hw_data *ha = base_vha->hw;
  1232. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1233. if (ret) {
  1234. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1235. "status %x\n", ret));
  1236. return (ret);
  1237. }
  1238. vha = qla24xx_create_vhost(fc_vport);
  1239. if (vha == NULL) {
  1240. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1241. vha));
  1242. return FC_VPORT_FAILED;
  1243. }
  1244. if (disable) {
  1245. atomic_set(&vha->vp_state, VP_OFFLINE);
  1246. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1247. } else
  1248. atomic_set(&vha->vp_state, VP_FAILED);
  1249. /* ready to create vport */
  1250. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1251. vha->vp_idx);
  1252. /* initialized vport states */
  1253. atomic_set(&vha->loop_state, LOOP_DOWN);
  1254. vha->vp_err_state= VP_ERR_PORTDWN;
  1255. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1256. /* Check if physical ha port is Up */
  1257. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1258. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1259. /* Don't retry or attempt login of this virtual port */
  1260. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1261. base_vha->host_no));
  1262. atomic_set(&vha->loop_state, LOOP_DEAD);
  1263. if (!disable)
  1264. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1265. }
  1266. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  1267. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1268. vha->host_no, vha->vp_idx));
  1269. goto vport_create_failed_2;
  1270. }
  1271. /* initialize attributes */
  1272. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1273. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1274. fc_host_supported_classes(vha->host) =
  1275. fc_host_supported_classes(base_vha->host);
  1276. fc_host_supported_speeds(vha->host) =
  1277. fc_host_supported_speeds(base_vha->host);
  1278. qla24xx_vport_disable(fc_vport, disable);
  1279. /* Create a queue pair for the vport */
  1280. if (ha->mqenable) {
  1281. if (ha->npiv_info) {
  1282. for (; cnt < ha->nvram_npiv_size; cnt++) {
  1283. if (ha->npiv_info[cnt].port_name ==
  1284. vha->port_name &&
  1285. ha->npiv_info[cnt].node_name ==
  1286. vha->node_name) {
  1287. qos = ha->npiv_info[cnt].q_qos;
  1288. break;
  1289. }
  1290. }
  1291. }
  1292. qla25xx_create_queues(vha, qos);
  1293. }
  1294. return 0;
  1295. vport_create_failed_2:
  1296. qla24xx_disable_vp(vha);
  1297. qla24xx_deallocate_vp_id(vha);
  1298. scsi_host_put(vha->host);
  1299. return FC_VPORT_FAILED;
  1300. }
  1301. static int
  1302. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1303. {
  1304. scsi_qla_host_t *vha = fc_vport->dd_data;
  1305. fc_port_t *fcport, *tfcport;
  1306. struct qla_hw_data *ha = vha->hw;
  1307. uint16_t id = vha->vp_idx;
  1308. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1309. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1310. msleep(1000);
  1311. qla24xx_disable_vp(vha);
  1312. fc_remove_host(vha->host);
  1313. scsi_remove_host(vha->host);
  1314. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1315. list_del(&fcport->list);
  1316. kfree(fcport);
  1317. fcport = NULL;
  1318. }
  1319. qla24xx_deallocate_vp_id(vha);
  1320. if (vha->timer_active) {
  1321. qla2x00_vp_stop_timer(vha);
  1322. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1323. "has stopped\n",
  1324. vha->host_no, vha->vp_idx, vha));
  1325. }
  1326. if (ha->mqenable) {
  1327. if (qla25xx_delete_queues(vha, 0) != QLA_SUCCESS)
  1328. qla_printk(KERN_WARNING, ha,
  1329. "Queue delete failed.\n");
  1330. }
  1331. scsi_host_put(vha->host);
  1332. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1333. return 0;
  1334. }
  1335. static int
  1336. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1337. {
  1338. scsi_qla_host_t *vha = fc_vport->dd_data;
  1339. if (disable)
  1340. qla24xx_disable_vp(vha);
  1341. else
  1342. qla24xx_enable_vp(vha);
  1343. return 0;
  1344. }
  1345. struct fc_function_template qla2xxx_transport_functions = {
  1346. .show_host_node_name = 1,
  1347. .show_host_port_name = 1,
  1348. .show_host_supported_classes = 1,
  1349. .show_host_supported_speeds = 1,
  1350. .get_host_port_id = qla2x00_get_host_port_id,
  1351. .show_host_port_id = 1,
  1352. .get_host_speed = qla2x00_get_host_speed,
  1353. .show_host_speed = 1,
  1354. .get_host_port_type = qla2x00_get_host_port_type,
  1355. .show_host_port_type = 1,
  1356. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1357. .show_host_symbolic_name = 1,
  1358. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1359. .show_host_system_hostname = 1,
  1360. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1361. .show_host_fabric_name = 1,
  1362. .get_host_port_state = qla2x00_get_host_port_state,
  1363. .show_host_port_state = 1,
  1364. .dd_fcrport_size = sizeof(struct fc_port *),
  1365. .show_rport_supported_classes = 1,
  1366. .get_starget_node_name = qla2x00_get_starget_node_name,
  1367. .show_starget_node_name = 1,
  1368. .get_starget_port_name = qla2x00_get_starget_port_name,
  1369. .show_starget_port_name = 1,
  1370. .get_starget_port_id = qla2x00_get_starget_port_id,
  1371. .show_starget_port_id = 1,
  1372. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1373. .show_rport_dev_loss_tmo = 1,
  1374. .issue_fc_host_lip = qla2x00_issue_lip,
  1375. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1376. .terminate_rport_io = qla2x00_terminate_rport_io,
  1377. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1378. .vport_create = qla24xx_vport_create,
  1379. .vport_disable = qla24xx_vport_disable,
  1380. .vport_delete = qla24xx_vport_delete,
  1381. };
  1382. struct fc_function_template qla2xxx_transport_vport_functions = {
  1383. .show_host_node_name = 1,
  1384. .show_host_port_name = 1,
  1385. .show_host_supported_classes = 1,
  1386. .get_host_port_id = qla2x00_get_host_port_id,
  1387. .show_host_port_id = 1,
  1388. .get_host_speed = qla2x00_get_host_speed,
  1389. .show_host_speed = 1,
  1390. .get_host_port_type = qla2x00_get_host_port_type,
  1391. .show_host_port_type = 1,
  1392. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1393. .show_host_symbolic_name = 1,
  1394. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1395. .show_host_system_hostname = 1,
  1396. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1397. .show_host_fabric_name = 1,
  1398. .get_host_port_state = qla2x00_get_host_port_state,
  1399. .show_host_port_state = 1,
  1400. .dd_fcrport_size = sizeof(struct fc_port *),
  1401. .show_rport_supported_classes = 1,
  1402. .get_starget_node_name = qla2x00_get_starget_node_name,
  1403. .show_starget_node_name = 1,
  1404. .get_starget_port_name = qla2x00_get_starget_port_name,
  1405. .show_starget_port_name = 1,
  1406. .get_starget_port_id = qla2x00_get_starget_port_id,
  1407. .show_starget_port_id = 1,
  1408. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1409. .show_rport_dev_loss_tmo = 1,
  1410. .issue_fc_host_lip = qla2x00_issue_lip,
  1411. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1412. .terminate_rport_io = qla2x00_terminate_rport_io,
  1413. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1414. };
  1415. void
  1416. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1417. {
  1418. struct qla_hw_data *ha = vha->hw;
  1419. u32 speed = FC_PORTSPEED_UNKNOWN;
  1420. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1421. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1422. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  1423. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1424. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1425. if (IS_QLA81XX(ha))
  1426. speed = FC_PORTSPEED_10GBIT;
  1427. else if (IS_QLA25XX(ha))
  1428. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1429. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1430. else if (IS_QLA24XX_TYPE(ha))
  1431. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1432. FC_PORTSPEED_1GBIT;
  1433. else if (IS_QLA23XX(ha))
  1434. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1435. else
  1436. speed = FC_PORTSPEED_1GBIT;
  1437. fc_host_supported_speeds(vha->host) = speed;
  1438. }