qla_attr.c 34 KB

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