qla_attr.c 34 KB

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