qla_attr.c 38 KB

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