qla_attr.c 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636
  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. static int qla84xx_reset(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  13. int qla84xx_reset_chip(scsi_qla_host_t *, uint16_t, uint16_t *);
  14. static int qla84xx_mgmt_cmd(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  15. /* SYSFS attributes --------------------------------------------------------- */
  16. static ssize_t
  17. qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
  18. struct bin_attribute *bin_attr,
  19. char *buf, loff_t off, size_t count)
  20. {
  21. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  22. struct device, kobj)));
  23. struct qla_hw_data *ha = vha->hw;
  24. if (ha->fw_dump_reading == 0)
  25. return 0;
  26. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  27. ha->fw_dump_len);
  28. }
  29. static ssize_t
  30. qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
  31. struct bin_attribute *bin_attr,
  32. char *buf, loff_t off, size_t count)
  33. {
  34. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  35. struct device, kobj)));
  36. struct qla_hw_data *ha = vha->hw;
  37. int reading;
  38. if (off != 0)
  39. return (0);
  40. reading = simple_strtol(buf, NULL, 10);
  41. switch (reading) {
  42. case 0:
  43. if (!ha->fw_dump_reading)
  44. break;
  45. qla_printk(KERN_INFO, ha,
  46. "Firmware dump cleared on (%ld).\n", vha->host_no);
  47. ha->fw_dump_reading = 0;
  48. ha->fw_dumped = 0;
  49. break;
  50. case 1:
  51. if (ha->fw_dumped && !ha->fw_dump_reading) {
  52. ha->fw_dump_reading = 1;
  53. qla_printk(KERN_INFO, ha,
  54. "Raw firmware dump ready for read on (%ld).\n",
  55. vha->host_no);
  56. }
  57. break;
  58. case 2:
  59. qla2x00_alloc_fw_dump(vha);
  60. break;
  61. case 3:
  62. qla2x00_system_error(vha);
  63. break;
  64. }
  65. return (count);
  66. }
  67. static struct bin_attribute sysfs_fw_dump_attr = {
  68. .attr = {
  69. .name = "fw_dump",
  70. .mode = S_IRUSR | S_IWUSR,
  71. },
  72. .size = 0,
  73. .read = qla2x00_sysfs_read_fw_dump,
  74. .write = qla2x00_sysfs_write_fw_dump,
  75. };
  76. static ssize_t
  77. qla2x00_sysfs_read_nvram(struct kobject *kobj,
  78. struct bin_attribute *bin_attr,
  79. char *buf, loff_t off, size_t count)
  80. {
  81. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  82. struct device, kobj)));
  83. struct qla_hw_data *ha = vha->hw;
  84. if (!capable(CAP_SYS_ADMIN))
  85. return 0;
  86. if (IS_NOCACHE_VPD_TYPE(ha))
  87. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  88. ha->nvram_size);
  89. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  90. ha->nvram_size);
  91. }
  92. static ssize_t
  93. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  94. struct bin_attribute *bin_attr,
  95. char *buf, loff_t off, size_t count)
  96. {
  97. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  98. struct device, kobj)));
  99. struct qla_hw_data *ha = vha->hw;
  100. uint16_t cnt;
  101. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  102. !ha->isp_ops->write_nvram)
  103. return 0;
  104. /* Checksum NVRAM. */
  105. if (IS_FWI2_CAPABLE(ha)) {
  106. uint32_t *iter;
  107. uint32_t chksum;
  108. iter = (uint32_t *)buf;
  109. chksum = 0;
  110. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  111. chksum += le32_to_cpu(*iter++);
  112. chksum = ~chksum + 1;
  113. *iter = cpu_to_le32(chksum);
  114. } else {
  115. uint8_t *iter;
  116. uint8_t chksum;
  117. iter = (uint8_t *)buf;
  118. chksum = 0;
  119. for (cnt = 0; cnt < count - 1; cnt++)
  120. chksum += *iter++;
  121. chksum = ~chksum + 1;
  122. *iter = chksum;
  123. }
  124. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  125. qla_printk(KERN_WARNING, ha,
  126. "HBA not online, failing NVRAM update.\n");
  127. return -EAGAIN;
  128. }
  129. /* Write NVRAM. */
  130. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  131. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  132. count);
  133. /* NVRAM settings take effect immediately. */
  134. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  135. qla2xxx_wake_dpc(vha);
  136. qla2x00_wait_for_chip_reset(vha);
  137. return (count);
  138. }
  139. static struct bin_attribute sysfs_nvram_attr = {
  140. .attr = {
  141. .name = "nvram",
  142. .mode = S_IRUSR | S_IWUSR,
  143. },
  144. .size = 512,
  145. .read = qla2x00_sysfs_read_nvram,
  146. .write = qla2x00_sysfs_write_nvram,
  147. };
  148. static ssize_t
  149. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  150. struct bin_attribute *bin_attr,
  151. char *buf, loff_t off, size_t count)
  152. {
  153. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  154. struct device, kobj)));
  155. struct qla_hw_data *ha = vha->hw;
  156. if (ha->optrom_state != QLA_SREADING)
  157. return 0;
  158. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  159. ha->optrom_region_size);
  160. }
  161. static ssize_t
  162. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  163. struct bin_attribute *bin_attr,
  164. char *buf, loff_t off, size_t count)
  165. {
  166. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  167. struct device, kobj)));
  168. struct qla_hw_data *ha = vha->hw;
  169. if (ha->optrom_state != QLA_SWRITING)
  170. return -EINVAL;
  171. if (off > ha->optrom_region_size)
  172. return -ERANGE;
  173. if (off + count > ha->optrom_region_size)
  174. count = ha->optrom_region_size - off;
  175. memcpy(&ha->optrom_buffer[off], buf, count);
  176. return count;
  177. }
  178. static struct bin_attribute sysfs_optrom_attr = {
  179. .attr = {
  180. .name = "optrom",
  181. .mode = S_IRUSR | S_IWUSR,
  182. },
  183. .size = 0,
  184. .read = qla2x00_sysfs_read_optrom,
  185. .write = qla2x00_sysfs_write_optrom,
  186. };
  187. static ssize_t
  188. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  189. struct bin_attribute *bin_attr,
  190. char *buf, loff_t off, size_t count)
  191. {
  192. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  193. struct device, kobj)));
  194. struct qla_hw_data *ha = vha->hw;
  195. uint32_t start = 0;
  196. uint32_t size = ha->optrom_size;
  197. int val, valid;
  198. if (off)
  199. return 0;
  200. if (unlikely(pci_channel_offline(ha->pdev)))
  201. return 0;
  202. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  203. return -EINVAL;
  204. if (start > ha->optrom_size)
  205. return -EINVAL;
  206. switch (val) {
  207. case 0:
  208. if (ha->optrom_state != QLA_SREADING &&
  209. ha->optrom_state != QLA_SWRITING)
  210. break;
  211. ha->optrom_state = QLA_SWAITING;
  212. DEBUG2(qla_printk(KERN_INFO, ha,
  213. "Freeing flash region allocation -- 0x%x bytes.\n",
  214. ha->optrom_region_size));
  215. vfree(ha->optrom_buffer);
  216. ha->optrom_buffer = NULL;
  217. break;
  218. case 1:
  219. if (ha->optrom_state != QLA_SWAITING)
  220. break;
  221. ha->optrom_region_start = start;
  222. ha->optrom_region_size = start + size > ha->optrom_size ?
  223. ha->optrom_size - start : size;
  224. ha->optrom_state = QLA_SREADING;
  225. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  226. if (ha->optrom_buffer == NULL) {
  227. qla_printk(KERN_WARNING, ha,
  228. "Unable to allocate memory for optrom retrieval "
  229. "(%x).\n", ha->optrom_region_size);
  230. ha->optrom_state = QLA_SWAITING;
  231. return count;
  232. }
  233. DEBUG2(qla_printk(KERN_INFO, ha,
  234. "Reading flash region -- 0x%x/0x%x.\n",
  235. ha->optrom_region_start, ha->optrom_region_size));
  236. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  237. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  238. ha->optrom_region_start, ha->optrom_region_size);
  239. break;
  240. case 2:
  241. if (ha->optrom_state != QLA_SWAITING)
  242. break;
  243. /*
  244. * We need to be more restrictive on which FLASH regions are
  245. * allowed to be updated via user-space. Regions accessible
  246. * via this method include:
  247. *
  248. * ISP21xx/ISP22xx/ISP23xx type boards:
  249. *
  250. * 0x000000 -> 0x020000 -- Boot code.
  251. *
  252. * ISP2322/ISP24xx type boards:
  253. *
  254. * 0x000000 -> 0x07ffff -- Boot code.
  255. * 0x080000 -> 0x0fffff -- Firmware.
  256. *
  257. * ISP25xx type boards:
  258. *
  259. * 0x000000 -> 0x07ffff -- Boot code.
  260. * 0x080000 -> 0x0fffff -- Firmware.
  261. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  262. */
  263. valid = 0;
  264. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  265. valid = 1;
  266. else if (start == (ha->flt_region_boot * 4) ||
  267. start == (ha->flt_region_fw * 4))
  268. valid = 1;
  269. else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
  270. valid = 1;
  271. if (!valid) {
  272. qla_printk(KERN_WARNING, ha,
  273. "Invalid start region 0x%x/0x%x.\n", start, size);
  274. return -EINVAL;
  275. }
  276. ha->optrom_region_start = start;
  277. ha->optrom_region_size = start + size > ha->optrom_size ?
  278. ha->optrom_size - start : size;
  279. ha->optrom_state = QLA_SWRITING;
  280. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  281. if (ha->optrom_buffer == NULL) {
  282. qla_printk(KERN_WARNING, ha,
  283. "Unable to allocate memory for optrom update "
  284. "(%x).\n", ha->optrom_region_size);
  285. ha->optrom_state = QLA_SWAITING;
  286. return count;
  287. }
  288. DEBUG2(qla_printk(KERN_INFO, ha,
  289. "Staging flash region write -- 0x%x/0x%x.\n",
  290. ha->optrom_region_start, ha->optrom_region_size));
  291. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  292. break;
  293. case 3:
  294. if (ha->optrom_state != QLA_SWRITING)
  295. break;
  296. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  297. qla_printk(KERN_WARNING, ha,
  298. "HBA not online, failing flash update.\n");
  299. return -EAGAIN;
  300. }
  301. DEBUG2(qla_printk(KERN_INFO, ha,
  302. "Writing flash region -- 0x%x/0x%x.\n",
  303. ha->optrom_region_start, ha->optrom_region_size));
  304. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  305. ha->optrom_region_start, ha->optrom_region_size);
  306. break;
  307. default:
  308. count = -EINVAL;
  309. }
  310. return count;
  311. }
  312. static struct bin_attribute sysfs_optrom_ctl_attr = {
  313. .attr = {
  314. .name = "optrom_ctl",
  315. .mode = S_IWUSR,
  316. },
  317. .size = 0,
  318. .write = qla2x00_sysfs_write_optrom_ctl,
  319. };
  320. static ssize_t
  321. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  322. struct bin_attribute *bin_attr,
  323. char *buf, loff_t off, size_t count)
  324. {
  325. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  326. struct device, kobj)));
  327. struct qla_hw_data *ha = vha->hw;
  328. if (unlikely(pci_channel_offline(ha->pdev)))
  329. return 0;
  330. if (!capable(CAP_SYS_ADMIN))
  331. return 0;
  332. if (IS_NOCACHE_VPD_TYPE(ha))
  333. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  334. ha->vpd_size);
  335. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  336. }
  337. static ssize_t
  338. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  339. struct bin_attribute *bin_attr,
  340. char *buf, loff_t off, size_t count)
  341. {
  342. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  343. struct device, kobj)));
  344. struct qla_hw_data *ha = vha->hw;
  345. uint8_t *tmp_data;
  346. if (unlikely(pci_channel_offline(ha->pdev)))
  347. return 0;
  348. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  349. !ha->isp_ops->write_nvram)
  350. return 0;
  351. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  352. qla_printk(KERN_WARNING, ha,
  353. "HBA not online, failing VPD update.\n");
  354. return -EAGAIN;
  355. }
  356. /* Write NVRAM. */
  357. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  358. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  359. /* Update flash version information for 4Gb & above. */
  360. if (!IS_FWI2_CAPABLE(ha))
  361. goto done;
  362. tmp_data = vmalloc(256);
  363. if (!tmp_data) {
  364. qla_printk(KERN_WARNING, ha,
  365. "Unable to allocate memory for VPD information update.\n");
  366. goto done;
  367. }
  368. ha->isp_ops->get_flash_version(vha, tmp_data);
  369. vfree(tmp_data);
  370. done:
  371. return count;
  372. }
  373. static struct bin_attribute sysfs_vpd_attr = {
  374. .attr = {
  375. .name = "vpd",
  376. .mode = S_IRUSR | S_IWUSR,
  377. },
  378. .size = 0,
  379. .read = qla2x00_sysfs_read_vpd,
  380. .write = qla2x00_sysfs_write_vpd,
  381. };
  382. static ssize_t
  383. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  384. struct bin_attribute *bin_attr,
  385. char *buf, loff_t off, size_t count)
  386. {
  387. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  388. struct device, kobj)));
  389. struct qla_hw_data *ha = vha->hw;
  390. uint16_t iter, addr, offset;
  391. int rval;
  392. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  393. return 0;
  394. if (ha->sfp_data)
  395. goto do_read;
  396. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  397. &ha->sfp_data_dma);
  398. if (!ha->sfp_data) {
  399. qla_printk(KERN_WARNING, ha,
  400. "Unable to allocate memory for SFP read-data.\n");
  401. return 0;
  402. }
  403. do_read:
  404. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  405. addr = 0xa0;
  406. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  407. iter++, offset += SFP_BLOCK_SIZE) {
  408. if (iter == 4) {
  409. /* Skip to next device address. */
  410. addr = 0xa2;
  411. offset = 0;
  412. }
  413. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  414. SFP_BLOCK_SIZE);
  415. if (rval != QLA_SUCCESS) {
  416. qla_printk(KERN_WARNING, ha,
  417. "Unable to read SFP data (%x/%x/%x).\n", rval,
  418. addr, offset);
  419. count = 0;
  420. break;
  421. }
  422. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  423. buf += SFP_BLOCK_SIZE;
  424. }
  425. return count;
  426. }
  427. static struct bin_attribute sysfs_sfp_attr = {
  428. .attr = {
  429. .name = "sfp",
  430. .mode = S_IRUSR | S_IWUSR,
  431. },
  432. .size = SFP_DEV_SIZE * 2,
  433. .read = qla2x00_sysfs_read_sfp,
  434. };
  435. static ssize_t
  436. qla2x00_sysfs_write_reset(struct kobject *kobj,
  437. struct bin_attribute *bin_attr,
  438. char *buf, loff_t off, size_t count)
  439. {
  440. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  441. struct device, kobj)));
  442. struct qla_hw_data *ha = vha->hw;
  443. int type;
  444. if (off != 0)
  445. return 0;
  446. type = simple_strtol(buf, NULL, 10);
  447. switch (type) {
  448. case 0x2025c:
  449. qla_printk(KERN_INFO, ha,
  450. "Issuing ISP reset on (%ld).\n", vha->host_no);
  451. scsi_block_requests(vha->host);
  452. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  453. qla2xxx_wake_dpc(vha);
  454. qla2x00_wait_for_chip_reset(vha);
  455. scsi_unblock_requests(vha->host);
  456. break;
  457. case 0x2025d:
  458. if (!IS_QLA81XX(ha))
  459. break;
  460. qla_printk(KERN_INFO, ha,
  461. "Issuing MPI reset on (%ld).\n", vha->host_no);
  462. /* Make sure FC side is not in reset */
  463. qla2x00_wait_for_hba_online(vha);
  464. /* Issue MPI reset */
  465. scsi_block_requests(vha->host);
  466. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  467. qla_printk(KERN_WARNING, ha,
  468. "MPI reset failed on (%ld).\n", vha->host_no);
  469. scsi_unblock_requests(vha->host);
  470. break;
  471. }
  472. return count;
  473. }
  474. static struct bin_attribute sysfs_reset_attr = {
  475. .attr = {
  476. .name = "reset",
  477. .mode = S_IWUSR,
  478. },
  479. .size = 0,
  480. .write = qla2x00_sysfs_write_reset,
  481. };
  482. static ssize_t
  483. qla2x00_sysfs_write_edc(struct kobject *kobj,
  484. struct bin_attribute *bin_attr,
  485. char *buf, loff_t off, size_t count)
  486. {
  487. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  488. struct device, kobj)));
  489. struct qla_hw_data *ha = vha->hw;
  490. uint16_t dev, adr, opt, len;
  491. int rval;
  492. ha->edc_data_len = 0;
  493. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  494. return 0;
  495. if (!ha->edc_data) {
  496. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  497. &ha->edc_data_dma);
  498. if (!ha->edc_data) {
  499. DEBUG2(qla_printk(KERN_INFO, ha,
  500. "Unable to allocate memory for EDC write.\n"));
  501. return 0;
  502. }
  503. }
  504. dev = le16_to_cpup((void *)&buf[0]);
  505. adr = le16_to_cpup((void *)&buf[2]);
  506. opt = le16_to_cpup((void *)&buf[4]);
  507. len = le16_to_cpup((void *)&buf[6]);
  508. if (!(opt & BIT_0))
  509. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  510. return -EINVAL;
  511. memcpy(ha->edc_data, &buf[8], len);
  512. rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
  513. ha->edc_data, len, opt);
  514. if (rval != QLA_SUCCESS) {
  515. DEBUG2(qla_printk(KERN_INFO, ha,
  516. "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
  517. rval, dev, adr, opt, len, *buf));
  518. return 0;
  519. }
  520. return count;
  521. }
  522. static struct bin_attribute sysfs_edc_attr = {
  523. .attr = {
  524. .name = "edc",
  525. .mode = S_IWUSR,
  526. },
  527. .size = 0,
  528. .write = qla2x00_sysfs_write_edc,
  529. };
  530. static ssize_t
  531. qla2x00_sysfs_write_edc_status(struct kobject *kobj,
  532. struct bin_attribute *bin_attr,
  533. char *buf, loff_t off, size_t count)
  534. {
  535. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  536. struct device, kobj)));
  537. struct qla_hw_data *ha = vha->hw;
  538. uint16_t dev, adr, opt, len;
  539. int rval;
  540. ha->edc_data_len = 0;
  541. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  542. return 0;
  543. if (!ha->edc_data) {
  544. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  545. &ha->edc_data_dma);
  546. if (!ha->edc_data) {
  547. DEBUG2(qla_printk(KERN_INFO, ha,
  548. "Unable to allocate memory for EDC status.\n"));
  549. return 0;
  550. }
  551. }
  552. dev = le16_to_cpup((void *)&buf[0]);
  553. adr = le16_to_cpup((void *)&buf[2]);
  554. opt = le16_to_cpup((void *)&buf[4]);
  555. len = le16_to_cpup((void *)&buf[6]);
  556. if (!(opt & BIT_0))
  557. if (len == 0 || len > DMA_POOL_SIZE)
  558. return -EINVAL;
  559. memset(ha->edc_data, 0, len);
  560. rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
  561. ha->edc_data, len, opt);
  562. if (rval != QLA_SUCCESS) {
  563. DEBUG2(qla_printk(KERN_INFO, ha,
  564. "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
  565. rval, dev, adr, opt, len));
  566. return 0;
  567. }
  568. ha->edc_data_len = len;
  569. return count;
  570. }
  571. static ssize_t
  572. qla2x00_sysfs_read_edc_status(struct kobject *kobj,
  573. struct bin_attribute *bin_attr,
  574. char *buf, loff_t off, size_t count)
  575. {
  576. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  577. struct device, kobj)));
  578. struct qla_hw_data *ha = vha->hw;
  579. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  580. return 0;
  581. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  582. return -EINVAL;
  583. memcpy(buf, ha->edc_data, ha->edc_data_len);
  584. return ha->edc_data_len;
  585. }
  586. static struct bin_attribute sysfs_edc_status_attr = {
  587. .attr = {
  588. .name = "edc_status",
  589. .mode = S_IRUSR | S_IWUSR,
  590. },
  591. .size = 0,
  592. .write = qla2x00_sysfs_write_edc_status,
  593. .read = qla2x00_sysfs_read_edc_status,
  594. };
  595. static ssize_t
  596. qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
  597. struct bin_attribute *bin_attr,
  598. char *buf, loff_t off, size_t count)
  599. {
  600. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  601. struct device, kobj)));
  602. struct qla_hw_data *ha = vha->hw;
  603. int rval;
  604. uint16_t actual_size;
  605. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  606. return 0;
  607. if (ha->xgmac_data)
  608. goto do_read;
  609. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  610. &ha->xgmac_data_dma, GFP_KERNEL);
  611. if (!ha->xgmac_data) {
  612. qla_printk(KERN_WARNING, ha,
  613. "Unable to allocate memory for XGMAC read-data.\n");
  614. return 0;
  615. }
  616. do_read:
  617. actual_size = 0;
  618. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  619. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  620. XGMAC_DATA_SIZE, &actual_size);
  621. if (rval != QLA_SUCCESS) {
  622. qla_printk(KERN_WARNING, ha,
  623. "Unable to read XGMAC data (%x).\n", rval);
  624. count = 0;
  625. }
  626. count = actual_size > count ? count: actual_size;
  627. memcpy(buf, ha->xgmac_data, count);
  628. return count;
  629. }
  630. static struct bin_attribute sysfs_xgmac_stats_attr = {
  631. .attr = {
  632. .name = "xgmac_stats",
  633. .mode = S_IRUSR,
  634. },
  635. .size = 0,
  636. .read = qla2x00_sysfs_read_xgmac_stats,
  637. };
  638. static ssize_t
  639. qla2x00_sysfs_read_dcbx_tlv(struct kobject *kobj,
  640. struct bin_attribute *bin_attr,
  641. char *buf, loff_t off, size_t count)
  642. {
  643. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  644. struct device, kobj)));
  645. struct qla_hw_data *ha = vha->hw;
  646. int rval;
  647. uint16_t actual_size;
  648. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  649. return 0;
  650. if (ha->dcbx_tlv)
  651. goto do_read;
  652. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  653. &ha->dcbx_tlv_dma, GFP_KERNEL);
  654. if (!ha->dcbx_tlv) {
  655. qla_printk(KERN_WARNING, ha,
  656. "Unable to allocate memory for DCBX TLV read-data.\n");
  657. return 0;
  658. }
  659. do_read:
  660. actual_size = 0;
  661. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  662. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  663. DCBX_TLV_DATA_SIZE);
  664. if (rval != QLA_SUCCESS) {
  665. qla_printk(KERN_WARNING, ha,
  666. "Unable to read DCBX TLV data (%x).\n", rval);
  667. count = 0;
  668. }
  669. memcpy(buf, ha->dcbx_tlv, count);
  670. return count;
  671. }
  672. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  673. .attr = {
  674. .name = "dcbx_tlv",
  675. .mode = S_IRUSR,
  676. },
  677. .size = 0,
  678. .read = qla2x00_sysfs_read_dcbx_tlv,
  679. };
  680. static struct sysfs_entry {
  681. char *name;
  682. struct bin_attribute *attr;
  683. int is4GBp_only;
  684. } bin_file_entries[] = {
  685. { "fw_dump", &sysfs_fw_dump_attr, },
  686. { "nvram", &sysfs_nvram_attr, },
  687. { "optrom", &sysfs_optrom_attr, },
  688. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  689. { "vpd", &sysfs_vpd_attr, 1 },
  690. { "sfp", &sysfs_sfp_attr, 1 },
  691. { "reset", &sysfs_reset_attr, },
  692. { "edc", &sysfs_edc_attr, 2 },
  693. { "edc_status", &sysfs_edc_status_attr, 2 },
  694. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  695. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  696. { NULL },
  697. };
  698. void
  699. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  700. {
  701. struct Scsi_Host *host = vha->host;
  702. struct sysfs_entry *iter;
  703. int ret;
  704. for (iter = bin_file_entries; iter->name; iter++) {
  705. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  706. continue;
  707. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  708. continue;
  709. if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
  710. continue;
  711. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  712. iter->attr);
  713. if (ret)
  714. qla_printk(KERN_INFO, vha->hw,
  715. "Unable to create sysfs %s binary attribute "
  716. "(%d).\n", iter->name, ret);
  717. }
  718. }
  719. void
  720. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  721. {
  722. struct Scsi_Host *host = vha->host;
  723. struct sysfs_entry *iter;
  724. struct qla_hw_data *ha = vha->hw;
  725. for (iter = bin_file_entries; iter->name; iter++) {
  726. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  727. continue;
  728. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  729. continue;
  730. if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
  731. continue;
  732. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  733. iter->attr);
  734. }
  735. if (ha->beacon_blink_led == 1)
  736. ha->isp_ops->beacon_off(vha);
  737. }
  738. /* Scsi_Host attributes. */
  739. static ssize_t
  740. qla2x00_drvr_version_show(struct device *dev,
  741. struct device_attribute *attr, char *buf)
  742. {
  743. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  744. }
  745. static ssize_t
  746. qla2x00_fw_version_show(struct device *dev,
  747. struct device_attribute *attr, char *buf)
  748. {
  749. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  750. struct qla_hw_data *ha = vha->hw;
  751. char fw_str[128];
  752. return snprintf(buf, PAGE_SIZE, "%s\n",
  753. ha->isp_ops->fw_version_str(vha, fw_str));
  754. }
  755. static ssize_t
  756. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  757. char *buf)
  758. {
  759. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  760. struct qla_hw_data *ha = vha->hw;
  761. uint32_t sn;
  762. if (IS_FWI2_CAPABLE(ha)) {
  763. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  764. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  765. }
  766. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  767. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  768. sn % 100000);
  769. }
  770. static ssize_t
  771. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  772. char *buf)
  773. {
  774. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  775. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  776. }
  777. static ssize_t
  778. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  779. char *buf)
  780. {
  781. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  782. struct qla_hw_data *ha = vha->hw;
  783. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  784. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  785. ha->product_id[3]);
  786. }
  787. static ssize_t
  788. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  789. char *buf)
  790. {
  791. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  792. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  793. }
  794. static ssize_t
  795. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  796. char *buf)
  797. {
  798. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  799. return snprintf(buf, PAGE_SIZE, "%s\n",
  800. vha->hw->model_desc ? vha->hw->model_desc : "");
  801. }
  802. static ssize_t
  803. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  804. char *buf)
  805. {
  806. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  807. char pci_info[30];
  808. return snprintf(buf, PAGE_SIZE, "%s\n",
  809. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  810. }
  811. static ssize_t
  812. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  813. char *buf)
  814. {
  815. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  816. struct qla_hw_data *ha = vha->hw;
  817. int len = 0;
  818. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  819. atomic_read(&vha->loop_state) == LOOP_DEAD)
  820. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  821. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  822. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  823. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  824. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  825. else {
  826. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  827. switch (ha->current_topology) {
  828. case ISP_CFG_NL:
  829. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  830. break;
  831. case ISP_CFG_FL:
  832. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  833. break;
  834. case ISP_CFG_N:
  835. len += snprintf(buf + len, PAGE_SIZE-len,
  836. "N_Port to N_Port\n");
  837. break;
  838. case ISP_CFG_F:
  839. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  840. break;
  841. default:
  842. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  843. break;
  844. }
  845. }
  846. return len;
  847. }
  848. static ssize_t
  849. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  850. char *buf)
  851. {
  852. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  853. int len = 0;
  854. switch (vha->hw->zio_mode) {
  855. case QLA_ZIO_MODE_6:
  856. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  857. break;
  858. case QLA_ZIO_DISABLED:
  859. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  860. break;
  861. }
  862. return len;
  863. }
  864. static ssize_t
  865. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  866. const char *buf, size_t count)
  867. {
  868. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  869. struct qla_hw_data *ha = vha->hw;
  870. int val = 0;
  871. uint16_t zio_mode;
  872. if (!IS_ZIO_SUPPORTED(ha))
  873. return -ENOTSUPP;
  874. if (sscanf(buf, "%d", &val) != 1)
  875. return -EINVAL;
  876. if (val)
  877. zio_mode = QLA_ZIO_MODE_6;
  878. else
  879. zio_mode = QLA_ZIO_DISABLED;
  880. /* Update per-hba values and queue a reset. */
  881. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  882. ha->zio_mode = zio_mode;
  883. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  884. }
  885. return strlen(buf);
  886. }
  887. static ssize_t
  888. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  889. char *buf)
  890. {
  891. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  892. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  893. }
  894. static ssize_t
  895. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  896. const char *buf, size_t count)
  897. {
  898. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  899. int val = 0;
  900. uint16_t zio_timer;
  901. if (sscanf(buf, "%d", &val) != 1)
  902. return -EINVAL;
  903. if (val > 25500 || val < 100)
  904. return -ERANGE;
  905. zio_timer = (uint16_t)(val / 100);
  906. vha->hw->zio_timer = zio_timer;
  907. return strlen(buf);
  908. }
  909. static ssize_t
  910. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  911. char *buf)
  912. {
  913. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  914. int len = 0;
  915. if (vha->hw->beacon_blink_led)
  916. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  917. else
  918. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  919. return len;
  920. }
  921. static ssize_t
  922. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  923. const char *buf, size_t count)
  924. {
  925. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  926. struct qla_hw_data *ha = vha->hw;
  927. int val = 0;
  928. int rval;
  929. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  930. return -EPERM;
  931. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  932. qla_printk(KERN_WARNING, ha,
  933. "Abort ISP active -- ignoring beacon request.\n");
  934. return -EBUSY;
  935. }
  936. if (sscanf(buf, "%d", &val) != 1)
  937. return -EINVAL;
  938. if (val)
  939. rval = ha->isp_ops->beacon_on(vha);
  940. else
  941. rval = ha->isp_ops->beacon_off(vha);
  942. if (rval != QLA_SUCCESS)
  943. count = 0;
  944. return count;
  945. }
  946. static ssize_t
  947. qla2x00_optrom_bios_version_show(struct device *dev,
  948. struct device_attribute *attr, char *buf)
  949. {
  950. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  951. struct qla_hw_data *ha = vha->hw;
  952. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  953. ha->bios_revision[0]);
  954. }
  955. static ssize_t
  956. qla2x00_optrom_efi_version_show(struct device *dev,
  957. struct device_attribute *attr, char *buf)
  958. {
  959. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  960. struct qla_hw_data *ha = vha->hw;
  961. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  962. ha->efi_revision[0]);
  963. }
  964. static ssize_t
  965. qla2x00_optrom_fcode_version_show(struct device *dev,
  966. struct device_attribute *attr, char *buf)
  967. {
  968. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  969. struct qla_hw_data *ha = vha->hw;
  970. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  971. ha->fcode_revision[0]);
  972. }
  973. static ssize_t
  974. qla2x00_optrom_fw_version_show(struct device *dev,
  975. struct device_attribute *attr, char *buf)
  976. {
  977. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  978. struct qla_hw_data *ha = vha->hw;
  979. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  980. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  981. ha->fw_revision[3]);
  982. }
  983. static ssize_t
  984. qla2x00_total_isp_aborts_show(struct device *dev,
  985. struct device_attribute *attr, char *buf)
  986. {
  987. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  988. struct qla_hw_data *ha = vha->hw;
  989. return snprintf(buf, PAGE_SIZE, "%d\n",
  990. ha->qla_stats.total_isp_aborts);
  991. }
  992. static ssize_t
  993. qla24xx_84xx_fw_version_show(struct device *dev,
  994. struct device_attribute *attr, char *buf)
  995. {
  996. int rval = QLA_SUCCESS;
  997. uint16_t status[2] = {0, 0};
  998. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  999. struct qla_hw_data *ha = vha->hw;
  1000. if (IS_QLA84XX(ha) && ha->cs84xx) {
  1001. if (ha->cs84xx->op_fw_version == 0) {
  1002. rval = qla84xx_verify_chip(vha, status);
  1003. }
  1004. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1005. return snprintf(buf, PAGE_SIZE, "%u\n",
  1006. (uint32_t)ha->cs84xx->op_fw_version);
  1007. }
  1008. return snprintf(buf, PAGE_SIZE, "\n");
  1009. }
  1010. static ssize_t
  1011. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1012. char *buf)
  1013. {
  1014. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1015. struct qla_hw_data *ha = vha->hw;
  1016. if (!IS_QLA81XX(ha))
  1017. return snprintf(buf, PAGE_SIZE, "\n");
  1018. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1019. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1020. ha->mpi_capabilities);
  1021. }
  1022. static ssize_t
  1023. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1024. char *buf)
  1025. {
  1026. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1027. struct qla_hw_data *ha = vha->hw;
  1028. if (!IS_QLA81XX(ha))
  1029. return snprintf(buf, PAGE_SIZE, "\n");
  1030. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1031. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1032. }
  1033. static ssize_t
  1034. qla2x00_flash_block_size_show(struct device *dev,
  1035. struct device_attribute *attr, char *buf)
  1036. {
  1037. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1038. struct qla_hw_data *ha = vha->hw;
  1039. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1040. }
  1041. static ssize_t
  1042. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1043. char *buf)
  1044. {
  1045. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1046. if (!IS_QLA81XX(vha->hw))
  1047. return snprintf(buf, PAGE_SIZE, "\n");
  1048. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1049. }
  1050. static ssize_t
  1051. qla2x00_vn_port_mac_address_show(struct device *dev,
  1052. struct device_attribute *attr, char *buf)
  1053. {
  1054. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1055. if (!IS_QLA81XX(vha->hw))
  1056. return snprintf(buf, PAGE_SIZE, "\n");
  1057. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1058. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1059. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1060. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1061. }
  1062. static ssize_t
  1063. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1064. char *buf)
  1065. {
  1066. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1067. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1068. }
  1069. static ssize_t
  1070. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1071. char *buf)
  1072. {
  1073. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1074. int rval = QLA_FUNCTION_FAILED;
  1075. uint16_t state[5];
  1076. if (!vha->hw->flags.eeh_busy)
  1077. rval = qla2x00_get_firmware_state(vha, state);
  1078. if (rval != QLA_SUCCESS)
  1079. memset(state, -1, sizeof(state));
  1080. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1081. state[1], state[2], state[3], state[4]);
  1082. }
  1083. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1084. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1085. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1086. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1087. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1088. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1089. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1090. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1091. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1092. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1093. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1094. qla2x00_zio_timer_store);
  1095. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1096. qla2x00_beacon_store);
  1097. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1098. qla2x00_optrom_bios_version_show, NULL);
  1099. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1100. qla2x00_optrom_efi_version_show, NULL);
  1101. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1102. qla2x00_optrom_fcode_version_show, NULL);
  1103. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1104. NULL);
  1105. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1106. NULL);
  1107. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1108. NULL);
  1109. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1110. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1111. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1112. NULL);
  1113. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1114. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1115. qla2x00_vn_port_mac_address_show, NULL);
  1116. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1117. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1118. struct device_attribute *qla2x00_host_attrs[] = {
  1119. &dev_attr_driver_version,
  1120. &dev_attr_fw_version,
  1121. &dev_attr_serial_num,
  1122. &dev_attr_isp_name,
  1123. &dev_attr_isp_id,
  1124. &dev_attr_model_name,
  1125. &dev_attr_model_desc,
  1126. &dev_attr_pci_info,
  1127. &dev_attr_link_state,
  1128. &dev_attr_zio,
  1129. &dev_attr_zio_timer,
  1130. &dev_attr_beacon,
  1131. &dev_attr_optrom_bios_version,
  1132. &dev_attr_optrom_efi_version,
  1133. &dev_attr_optrom_fcode_version,
  1134. &dev_attr_optrom_fw_version,
  1135. &dev_attr_84xx_fw_version,
  1136. &dev_attr_total_isp_aborts,
  1137. &dev_attr_mpi_version,
  1138. &dev_attr_phy_version,
  1139. &dev_attr_flash_block_size,
  1140. &dev_attr_vlan_id,
  1141. &dev_attr_vn_port_mac_address,
  1142. &dev_attr_fabric_param,
  1143. &dev_attr_fw_state,
  1144. NULL,
  1145. };
  1146. /* Host attributes. */
  1147. static void
  1148. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1149. {
  1150. scsi_qla_host_t *vha = shost_priv(shost);
  1151. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1152. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1153. }
  1154. static void
  1155. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1156. {
  1157. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1158. (shost_priv(shost)))->hw;
  1159. u32 speed = FC_PORTSPEED_UNKNOWN;
  1160. switch (ha->link_data_rate) {
  1161. case PORT_SPEED_1GB:
  1162. speed = FC_PORTSPEED_1GBIT;
  1163. break;
  1164. case PORT_SPEED_2GB:
  1165. speed = FC_PORTSPEED_2GBIT;
  1166. break;
  1167. case PORT_SPEED_4GB:
  1168. speed = FC_PORTSPEED_4GBIT;
  1169. break;
  1170. case PORT_SPEED_8GB:
  1171. speed = FC_PORTSPEED_8GBIT;
  1172. break;
  1173. case PORT_SPEED_10GB:
  1174. speed = FC_PORTSPEED_10GBIT;
  1175. break;
  1176. }
  1177. fc_host_speed(shost) = speed;
  1178. }
  1179. static void
  1180. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1181. {
  1182. scsi_qla_host_t *vha = shost_priv(shost);
  1183. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1184. if (vha->vp_idx) {
  1185. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1186. return;
  1187. }
  1188. switch (vha->hw->current_topology) {
  1189. case ISP_CFG_NL:
  1190. port_type = FC_PORTTYPE_LPORT;
  1191. break;
  1192. case ISP_CFG_FL:
  1193. port_type = FC_PORTTYPE_NLPORT;
  1194. break;
  1195. case ISP_CFG_N:
  1196. port_type = FC_PORTTYPE_PTP;
  1197. break;
  1198. case ISP_CFG_F:
  1199. port_type = FC_PORTTYPE_NPORT;
  1200. break;
  1201. }
  1202. fc_host_port_type(shost) = port_type;
  1203. }
  1204. static void
  1205. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1206. {
  1207. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1208. scsi_qla_host_t *vha = shost_priv(host);
  1209. fc_port_t *fcport;
  1210. u64 node_name = 0;
  1211. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1212. if (fcport->rport &&
  1213. starget->id == fcport->rport->scsi_target_id) {
  1214. node_name = wwn_to_u64(fcport->node_name);
  1215. break;
  1216. }
  1217. }
  1218. fc_starget_node_name(starget) = node_name;
  1219. }
  1220. static void
  1221. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1222. {
  1223. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1224. scsi_qla_host_t *vha = shost_priv(host);
  1225. fc_port_t *fcport;
  1226. u64 port_name = 0;
  1227. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1228. if (fcport->rport &&
  1229. starget->id == fcport->rport->scsi_target_id) {
  1230. port_name = wwn_to_u64(fcport->port_name);
  1231. break;
  1232. }
  1233. }
  1234. fc_starget_port_name(starget) = port_name;
  1235. }
  1236. static void
  1237. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1238. {
  1239. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1240. scsi_qla_host_t *vha = shost_priv(host);
  1241. fc_port_t *fcport;
  1242. uint32_t port_id = ~0U;
  1243. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1244. if (fcport->rport &&
  1245. starget->id == fcport->rport->scsi_target_id) {
  1246. port_id = fcport->d_id.b.domain << 16 |
  1247. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1248. break;
  1249. }
  1250. }
  1251. fc_starget_port_id(starget) = port_id;
  1252. }
  1253. static void
  1254. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1255. {
  1256. if (timeout)
  1257. rport->dev_loss_tmo = timeout;
  1258. else
  1259. rport->dev_loss_tmo = 1;
  1260. }
  1261. static void
  1262. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1263. {
  1264. struct Scsi_Host *host = rport_to_shost(rport);
  1265. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1266. if (!fcport)
  1267. return;
  1268. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1269. return;
  1270. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1271. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1272. return;
  1273. }
  1274. /*
  1275. * Transport has effectively 'deleted' the rport, clear
  1276. * all local references.
  1277. */
  1278. spin_lock_irq(host->host_lock);
  1279. fcport->rport = NULL;
  1280. *((fc_port_t **)rport->dd_data) = NULL;
  1281. spin_unlock_irq(host->host_lock);
  1282. }
  1283. static void
  1284. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1285. {
  1286. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1287. if (!fcport)
  1288. return;
  1289. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1290. return;
  1291. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1292. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1293. return;
  1294. }
  1295. /*
  1296. * At this point all fcport's software-states are cleared. Perform any
  1297. * final cleanup of firmware resources (PCBs and XCBs).
  1298. */
  1299. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1300. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1301. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1302. fcport->loop_id, fcport->d_id.b.domain,
  1303. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1304. qla2x00_abort_fcport_cmds(fcport);
  1305. }
  1306. static int
  1307. qla2x00_issue_lip(struct Scsi_Host *shost)
  1308. {
  1309. scsi_qla_host_t *vha = shost_priv(shost);
  1310. qla2x00_loop_reset(vha);
  1311. return 0;
  1312. }
  1313. static struct fc_host_statistics *
  1314. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1315. {
  1316. scsi_qla_host_t *vha = shost_priv(shost);
  1317. struct qla_hw_data *ha = vha->hw;
  1318. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1319. int rval;
  1320. struct link_statistics *stats;
  1321. dma_addr_t stats_dma;
  1322. struct fc_host_statistics *pfc_host_stat;
  1323. pfc_host_stat = &ha->fc_host_stat;
  1324. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1325. if (test_bit(UNLOADING, &vha->dpc_flags))
  1326. goto done;
  1327. if (unlikely(pci_channel_offline(ha->pdev)))
  1328. goto done;
  1329. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1330. if (stats == NULL) {
  1331. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1332. __func__, base_vha->host_no));
  1333. goto done;
  1334. }
  1335. memset(stats, 0, DMA_POOL_SIZE);
  1336. rval = QLA_FUNCTION_FAILED;
  1337. if (IS_FWI2_CAPABLE(ha)) {
  1338. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1339. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1340. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1341. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1342. !ha->dpc_active) {
  1343. /* Must be in a 'READY' state for statistics retrieval. */
  1344. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1345. stats, stats_dma);
  1346. }
  1347. if (rval != QLA_SUCCESS)
  1348. goto done_free;
  1349. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1350. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1351. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1352. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1353. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1354. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1355. if (IS_FWI2_CAPABLE(ha)) {
  1356. pfc_host_stat->lip_count = stats->lip_cnt;
  1357. pfc_host_stat->tx_frames = stats->tx_frames;
  1358. pfc_host_stat->rx_frames = stats->rx_frames;
  1359. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1360. pfc_host_stat->nos_count = stats->nos_rcvd;
  1361. }
  1362. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1363. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1364. done_free:
  1365. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1366. done:
  1367. return pfc_host_stat;
  1368. }
  1369. static void
  1370. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1371. {
  1372. scsi_qla_host_t *vha = shost_priv(shost);
  1373. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1374. }
  1375. static void
  1376. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1377. {
  1378. scsi_qla_host_t *vha = shost_priv(shost);
  1379. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1380. }
  1381. static void
  1382. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1383. {
  1384. scsi_qla_host_t *vha = shost_priv(shost);
  1385. u64 node_name;
  1386. if (vha->device_flags & SWITCH_FOUND)
  1387. node_name = wwn_to_u64(vha->fabric_node_name);
  1388. else
  1389. node_name = wwn_to_u64(vha->node_name);
  1390. fc_host_fabric_name(shost) = node_name;
  1391. }
  1392. static void
  1393. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1394. {
  1395. scsi_qla_host_t *vha = shost_priv(shost);
  1396. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1397. if (!base_vha->flags.online)
  1398. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1399. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1400. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1401. else
  1402. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1403. }
  1404. static int
  1405. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1406. {
  1407. int ret = 0;
  1408. uint8_t qos = 0;
  1409. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1410. scsi_qla_host_t *vha = NULL;
  1411. struct qla_hw_data *ha = base_vha->hw;
  1412. uint16_t options = 0;
  1413. int cnt;
  1414. struct req_que *req = ha->req_q_map[0];
  1415. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1416. if (ret) {
  1417. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1418. "status %x\n", ret));
  1419. return (ret);
  1420. }
  1421. vha = qla24xx_create_vhost(fc_vport);
  1422. if (vha == NULL) {
  1423. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1424. vha));
  1425. return FC_VPORT_FAILED;
  1426. }
  1427. if (disable) {
  1428. atomic_set(&vha->vp_state, VP_OFFLINE);
  1429. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1430. } else
  1431. atomic_set(&vha->vp_state, VP_FAILED);
  1432. /* ready to create vport */
  1433. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1434. vha->vp_idx);
  1435. /* initialized vport states */
  1436. atomic_set(&vha->loop_state, LOOP_DOWN);
  1437. vha->vp_err_state= VP_ERR_PORTDWN;
  1438. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1439. /* Check if physical ha port is Up */
  1440. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1441. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1442. /* Don't retry or attempt login of this virtual port */
  1443. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1444. base_vha->host_no));
  1445. atomic_set(&vha->loop_state, LOOP_DEAD);
  1446. if (!disable)
  1447. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1448. }
  1449. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1450. &ha->pdev->dev)) {
  1451. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1452. vha->host_no, vha->vp_idx));
  1453. goto vport_create_failed_2;
  1454. }
  1455. /* initialize attributes */
  1456. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1457. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1458. fc_host_supported_classes(vha->host) =
  1459. fc_host_supported_classes(base_vha->host);
  1460. fc_host_supported_speeds(vha->host) =
  1461. fc_host_supported_speeds(base_vha->host);
  1462. qla24xx_vport_disable(fc_vport, disable);
  1463. if (ha->flags.cpu_affinity_enabled) {
  1464. req = ha->req_q_map[1];
  1465. goto vport_queue;
  1466. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1467. goto vport_queue;
  1468. /* Create a request queue in QoS mode for the vport */
  1469. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1470. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1471. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1472. 8) == 0) {
  1473. qos = ha->npiv_info[cnt].q_qos;
  1474. break;
  1475. }
  1476. }
  1477. if (qos) {
  1478. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1479. qos);
  1480. if (!ret)
  1481. qla_printk(KERN_WARNING, ha,
  1482. "Can't create request queue for vp_idx:%d\n",
  1483. vha->vp_idx);
  1484. else {
  1485. DEBUG2(qla_printk(KERN_INFO, ha,
  1486. "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
  1487. ret, qos, vha->vp_idx));
  1488. req = ha->req_q_map[ret];
  1489. }
  1490. }
  1491. vport_queue:
  1492. vha->req = req;
  1493. return 0;
  1494. vport_create_failed_2:
  1495. qla24xx_disable_vp(vha);
  1496. qla24xx_deallocate_vp_id(vha);
  1497. scsi_host_put(vha->host);
  1498. return FC_VPORT_FAILED;
  1499. }
  1500. static int
  1501. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1502. {
  1503. scsi_qla_host_t *vha = fc_vport->dd_data;
  1504. fc_port_t *fcport, *tfcport;
  1505. struct qla_hw_data *ha = vha->hw;
  1506. uint16_t id = vha->vp_idx;
  1507. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1508. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1509. msleep(1000);
  1510. qla24xx_disable_vp(vha);
  1511. fc_remove_host(vha->host);
  1512. scsi_remove_host(vha->host);
  1513. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1514. list_del(&fcport->list);
  1515. kfree(fcport);
  1516. fcport = NULL;
  1517. }
  1518. qla24xx_deallocate_vp_id(vha);
  1519. mutex_lock(&ha->vport_lock);
  1520. ha->cur_vport_count--;
  1521. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1522. mutex_unlock(&ha->vport_lock);
  1523. if (vha->timer_active) {
  1524. qla2x00_vp_stop_timer(vha);
  1525. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1526. "has stopped\n",
  1527. vha->host_no, vha->vp_idx, vha));
  1528. }
  1529. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1530. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1531. qla_printk(KERN_WARNING, ha,
  1532. "Queue delete failed.\n");
  1533. }
  1534. scsi_host_put(vha->host);
  1535. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1536. return 0;
  1537. }
  1538. static int
  1539. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1540. {
  1541. scsi_qla_host_t *vha = fc_vport->dd_data;
  1542. if (disable)
  1543. qla24xx_disable_vp(vha);
  1544. else
  1545. qla24xx_enable_vp(vha);
  1546. return 0;
  1547. }
  1548. /* BSG support for ELS/CT pass through */
  1549. inline srb_t *
  1550. qla2x00_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size)
  1551. {
  1552. srb_t *sp;
  1553. struct qla_hw_data *ha = vha->hw;
  1554. struct srb_bsg_ctx *ctx;
  1555. sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
  1556. if (!sp)
  1557. goto done;
  1558. ctx = kzalloc(size, GFP_KERNEL);
  1559. if (!ctx) {
  1560. mempool_free(sp, ha->srb_mempool);
  1561. goto done;
  1562. }
  1563. memset(sp, 0, sizeof(*sp));
  1564. sp->fcport = fcport;
  1565. sp->ctx = ctx;
  1566. done:
  1567. return sp;
  1568. }
  1569. static int
  1570. qla2x00_process_els(struct fc_bsg_job *bsg_job)
  1571. {
  1572. struct fc_rport *rport;
  1573. fc_port_t *fcport;
  1574. struct Scsi_Host *host;
  1575. scsi_qla_host_t *vha;
  1576. struct qla_hw_data *ha;
  1577. srb_t *sp;
  1578. const char *type;
  1579. int req_sg_cnt, rsp_sg_cnt;
  1580. int rval = (DRIVER_ERROR << 16);
  1581. uint16_t nextlid = 0;
  1582. struct srb_bsg *els;
  1583. /* Multiple SG's are not supported for ELS requests */
  1584. if (bsg_job->request_payload.sg_cnt > 1 ||
  1585. bsg_job->reply_payload.sg_cnt > 1) {
  1586. DEBUG2(printk(KERN_INFO
  1587. "multiple SG's are not supported for ELS requests"
  1588. " [request_sg_cnt: %x reply_sg_cnt: %x]\n",
  1589. bsg_job->request_payload.sg_cnt,
  1590. bsg_job->reply_payload.sg_cnt));
  1591. rval = -EPERM;
  1592. goto done;
  1593. }
  1594. /* ELS request for rport */
  1595. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  1596. rport = bsg_job->rport;
  1597. fcport = *(fc_port_t **) rport->dd_data;
  1598. host = rport_to_shost(rport);
  1599. vha = shost_priv(host);
  1600. ha = vha->hw;
  1601. type = "FC_BSG_RPT_ELS";
  1602. /* make sure the rport is logged in,
  1603. * if not perform fabric login
  1604. */
  1605. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  1606. DEBUG2(qla_printk(KERN_WARNING, ha,
  1607. "failed to login port %06X for ELS passthru\n",
  1608. fcport->d_id.b24));
  1609. rval = -EIO;
  1610. goto done;
  1611. }
  1612. } else {
  1613. host = bsg_job->shost;
  1614. vha = shost_priv(host);
  1615. ha = vha->hw;
  1616. type = "FC_BSG_HST_ELS_NOLOGIN";
  1617. /* Allocate a dummy fcport structure, since functions
  1618. * preparing the IOCB and mailbox command retrieves port
  1619. * specific information from fcport structure. For Host based
  1620. * ELS commands there will be no fcport structure allocated
  1621. */
  1622. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1623. if (!fcport) {
  1624. rval = -ENOMEM;
  1625. goto done;
  1626. }
  1627. /* Initialize all required fields of fcport */
  1628. fcport->vha = vha;
  1629. fcport->vp_idx = vha->vp_idx;
  1630. fcport->d_id.b.al_pa =
  1631. bsg_job->request->rqst_data.h_els.port_id[0];
  1632. fcport->d_id.b.area =
  1633. bsg_job->request->rqst_data.h_els.port_id[1];
  1634. fcport->d_id.b.domain =
  1635. bsg_job->request->rqst_data.h_els.port_id[2];
  1636. fcport->loop_id =
  1637. (fcport->d_id.b.al_pa == 0xFD) ?
  1638. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  1639. }
  1640. if (!vha->flags.online) {
  1641. DEBUG2(qla_printk(KERN_WARNING, ha,
  1642. "host not online\n"));
  1643. rval = -EIO;
  1644. goto done;
  1645. }
  1646. req_sg_cnt =
  1647. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1648. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1649. if (!req_sg_cnt) {
  1650. rval = -ENOMEM;
  1651. goto done_free_fcport;
  1652. }
  1653. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1654. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1655. if (!rsp_sg_cnt) {
  1656. rval = -ENOMEM;
  1657. goto done_free_fcport;
  1658. }
  1659. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1660. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1661. {
  1662. DEBUG2(printk(KERN_INFO
  1663. "dma mapping resulted in different sg counts \
  1664. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1665. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1666. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1667. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1668. rval = -EAGAIN;
  1669. goto done_unmap_sg;
  1670. }
  1671. /* Alloc SRB structure */
  1672. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1673. if (!sp) {
  1674. rval = -ENOMEM;
  1675. goto done_unmap_sg;
  1676. }
  1677. els = sp->ctx;
  1678. els->ctx.type =
  1679. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  1680. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  1681. els->bsg_job = bsg_job;
  1682. DEBUG2(qla_printk(KERN_INFO, ha,
  1683. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1684. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1685. bsg_job->request->rqst_data.h_els.command_code,
  1686. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1687. fcport->d_id.b.al_pa));
  1688. rval = qla2x00_start_sp(sp);
  1689. if (rval != QLA_SUCCESS) {
  1690. kfree(sp->ctx);
  1691. mempool_free(sp, ha->srb_mempool);
  1692. rval = -EIO;
  1693. goto done_unmap_sg;
  1694. }
  1695. return rval;
  1696. done_unmap_sg:
  1697. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1698. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1699. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1700. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1701. goto done_free_fcport;
  1702. done_free_fcport:
  1703. if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
  1704. kfree(fcport);
  1705. done:
  1706. return rval;
  1707. }
  1708. static int
  1709. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  1710. {
  1711. srb_t *sp;
  1712. struct Scsi_Host *host = bsg_job->shost;
  1713. scsi_qla_host_t *vha = shost_priv(host);
  1714. struct qla_hw_data *ha = vha->hw;
  1715. int rval = (DRIVER_ERROR << 16);
  1716. int req_sg_cnt, rsp_sg_cnt;
  1717. uint16_t loop_id;
  1718. struct fc_port *fcport;
  1719. char *type = "FC_BSG_HST_CT";
  1720. struct srb_bsg *ct;
  1721. /* pass through is supported only for ISP 4Gb or higher */
  1722. if (!IS_FWI2_CAPABLE(ha)) {
  1723. DEBUG2(qla_printk(KERN_INFO, ha,
  1724. "scsi(%ld):Firmware is not capable to support FC "
  1725. "CT pass thru\n", vha->host_no));
  1726. rval = -EPERM;
  1727. goto done;
  1728. }
  1729. req_sg_cnt =
  1730. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1731. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1732. if (!req_sg_cnt) {
  1733. rval = -ENOMEM;
  1734. goto done;
  1735. }
  1736. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1737. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1738. if (!rsp_sg_cnt) {
  1739. rval = -ENOMEM;
  1740. goto done;
  1741. }
  1742. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1743. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1744. {
  1745. DEBUG2(qla_printk(KERN_WARNING, ha,
  1746. "dma mapping resulted in different sg counts \
  1747. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1748. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1749. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1750. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1751. rval = -EAGAIN;
  1752. goto done_unmap_sg;
  1753. }
  1754. if (!vha->flags.online) {
  1755. DEBUG2(qla_printk(KERN_WARNING, ha,
  1756. "host not online\n"));
  1757. rval = -EIO;
  1758. goto done_unmap_sg;
  1759. }
  1760. loop_id =
  1761. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  1762. >> 24;
  1763. switch (loop_id) {
  1764. case 0xFC:
  1765. loop_id = cpu_to_le16(NPH_SNS);
  1766. break;
  1767. case 0xFA:
  1768. loop_id = vha->mgmt_svr_loop_id;
  1769. break;
  1770. default:
  1771. DEBUG2(qla_printk(KERN_INFO, ha,
  1772. "Unknown loop id: %x\n", loop_id));
  1773. rval = -EINVAL;
  1774. goto done_unmap_sg;
  1775. }
  1776. /* Allocate a dummy fcport structure, since functions preparing the
  1777. * IOCB and mailbox command retrieves port specific information
  1778. * from fcport structure. For Host based ELS commands there will be
  1779. * no fcport structure allocated
  1780. */
  1781. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1782. if (!fcport)
  1783. {
  1784. rval = -ENOMEM;
  1785. goto done_unmap_sg;
  1786. }
  1787. /* Initialize all required fields of fcport */
  1788. fcport->vha = vha;
  1789. fcport->vp_idx = vha->vp_idx;
  1790. fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
  1791. fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
  1792. fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
  1793. fcport->loop_id = loop_id;
  1794. /* Alloc SRB structure */
  1795. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1796. if (!sp) {
  1797. rval = -ENOMEM;
  1798. goto done_free_fcport;
  1799. }
  1800. ct = sp->ctx;
  1801. ct->ctx.type = SRB_CT_CMD;
  1802. ct->bsg_job = bsg_job;
  1803. DEBUG2(qla_printk(KERN_INFO, ha,
  1804. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1805. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1806. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  1807. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1808. fcport->d_id.b.al_pa));
  1809. rval = qla2x00_start_sp(sp);
  1810. if (rval != QLA_SUCCESS) {
  1811. kfree(sp->ctx);
  1812. mempool_free(sp, ha->srb_mempool);
  1813. rval = -EIO;
  1814. goto done_free_fcport;
  1815. }
  1816. return rval;
  1817. done_free_fcport:
  1818. kfree(fcport);
  1819. done_unmap_sg:
  1820. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1821. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1822. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1823. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1824. done:
  1825. return rval;
  1826. }
  1827. static int
  1828. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1829. {
  1830. struct Scsi_Host *host = bsg_job->shost;
  1831. scsi_qla_host_t *vha = shost_priv(host);
  1832. struct qla_hw_data *ha = vha->hw;
  1833. int rval;
  1834. uint8_t command_sent;
  1835. uint32_t vendor_cmd;
  1836. char *type;
  1837. struct msg_echo_lb elreq;
  1838. uint16_t response[MAILBOX_REGISTER_COUNT];
  1839. uint8_t* fw_sts_ptr;
  1840. uint8_t *req_data;
  1841. dma_addr_t req_data_dma;
  1842. uint32_t req_data_len;
  1843. uint8_t *rsp_data;
  1844. dma_addr_t rsp_data_dma;
  1845. uint32_t rsp_data_len;
  1846. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  1847. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1848. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  1849. rval = -EBUSY;
  1850. goto done;
  1851. }
  1852. if (!vha->flags.online) {
  1853. DEBUG2(qla_printk(KERN_WARNING, ha,
  1854. "host not online\n"));
  1855. rval = -EIO;
  1856. goto done;
  1857. }
  1858. elreq.req_sg_cnt =
  1859. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1860. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1861. if (!elreq.req_sg_cnt) {
  1862. rval = -ENOMEM;
  1863. goto done;
  1864. }
  1865. elreq.rsp_sg_cnt =
  1866. dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1867. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1868. if (!elreq.rsp_sg_cnt) {
  1869. rval = -ENOMEM;
  1870. goto done;
  1871. }
  1872. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1873. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1874. {
  1875. DEBUG2(printk(KERN_INFO
  1876. "dma mapping resulted in different sg counts \
  1877. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1878. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1879. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  1880. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
  1881. rval = -EAGAIN;
  1882. goto done_unmap_sg;
  1883. }
  1884. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  1885. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  1886. &req_data_dma, GFP_KERNEL);
  1887. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  1888. &rsp_data_dma, GFP_KERNEL);
  1889. /* Copy the request buffer in req_data now */
  1890. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1891. bsg_job->request_payload.sg_cnt, req_data,
  1892. req_data_len);
  1893. elreq.send_dma = req_data_dma;
  1894. elreq.rcv_dma = rsp_data_dma;
  1895. elreq.transfer_size = req_data_len;
  1896. /* Vendor cmd : loopback or ECHO diagnostic
  1897. * Options:
  1898. * Loopback : Either internal or external loopback
  1899. * ECHO: ECHO ELS or Vendor specific FC4 link data
  1900. */
  1901. vendor_cmd = bsg_job->request->rqst_data.h_vendor.vendor_cmd[0];
  1902. elreq.options =
  1903. *(((uint32_t *)bsg_job->request->rqst_data.h_vendor.vendor_cmd)
  1904. + 1);
  1905. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1906. case QL_VND_LOOPBACK:
  1907. if (ha->current_topology != ISP_CFG_F) {
  1908. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  1909. DEBUG2(qla_printk(KERN_INFO, ha,
  1910. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1911. vha->host_no, type, vendor_cmd, elreq.options));
  1912. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  1913. rval = qla2x00_loopback_test(vha, &elreq, response);
  1914. if (IS_QLA81XX(ha)) {
  1915. if (response[0] == MBS_COMMAND_ERROR && response[1] == MBS_LB_RESET) {
  1916. DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
  1917. "ISP\n", __func__, vha->host_no));
  1918. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1919. qla2xxx_wake_dpc(vha);
  1920. }
  1921. }
  1922. } else {
  1923. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  1924. DEBUG2(qla_printk(KERN_INFO, ha,
  1925. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1926. vha->host_no, type, vendor_cmd, elreq.options));
  1927. command_sent = INT_DEF_LB_ECHO_CMD;
  1928. rval = qla2x00_echo_test(vha, &elreq, response);
  1929. }
  1930. break;
  1931. case QLA84_RESET:
  1932. if (!IS_QLA84XX(vha->hw)) {
  1933. rval = -EINVAL;
  1934. DEBUG16(printk(
  1935. "%s(%ld): 8xxx exiting.\n",
  1936. __func__, vha->host_no));
  1937. return rval;
  1938. }
  1939. rval = qla84xx_reset(vha, &elreq, bsg_job);
  1940. break;
  1941. case QLA84_MGMT_CMD:
  1942. if (!IS_QLA84XX(vha->hw)) {
  1943. rval = -EINVAL;
  1944. DEBUG16(printk(
  1945. "%s(%ld): 8xxx exiting.\n",
  1946. __func__, vha->host_no));
  1947. return rval;
  1948. }
  1949. rval = qla84xx_mgmt_cmd(vha, &elreq, bsg_job);
  1950. break;
  1951. default:
  1952. rval = -ENOSYS;
  1953. }
  1954. if (rval != QLA_SUCCESS) {
  1955. DEBUG2(qla_printk(KERN_WARNING, ha,
  1956. "scsi(%ld) Vendor request %s failed\n", vha->host_no, type));
  1957. rval = 0;
  1958. bsg_job->reply->result = (DID_ERROR << 16);
  1959. bsg_job->reply->reply_payload_rcv_len = 0;
  1960. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1961. memcpy( fw_sts_ptr, response, sizeof(response));
  1962. fw_sts_ptr += sizeof(response);
  1963. *fw_sts_ptr = command_sent;
  1964. } else {
  1965. DEBUG2(qla_printk(KERN_WARNING, ha,
  1966. "scsi(%ld) Vendor request %s completed\n", vha->host_no, type));
  1967. rval = bsg_job->reply->result = 0;
  1968. bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(response) + sizeof(uint8_t);
  1969. bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
  1970. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1971. memcpy(fw_sts_ptr, response, sizeof(response));
  1972. fw_sts_ptr += sizeof(response);
  1973. *fw_sts_ptr = command_sent;
  1974. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1975. bsg_job->reply_payload.sg_cnt, rsp_data,
  1976. rsp_data_len);
  1977. }
  1978. bsg_job->job_done(bsg_job);
  1979. done_unmap_sg:
  1980. if(req_data)
  1981. dma_free_coherent(&ha->pdev->dev, req_data_len,
  1982. req_data, req_data_dma);
  1983. dma_unmap_sg(&ha->pdev->dev,
  1984. bsg_job->request_payload.sg_list,
  1985. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1986. dma_unmap_sg(&ha->pdev->dev,
  1987. bsg_job->reply_payload.sg_list,
  1988. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1989. done:
  1990. return rval;
  1991. }
  1992. static int
  1993. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  1994. {
  1995. int ret = -EINVAL;
  1996. switch (bsg_job->request->msgcode) {
  1997. case FC_BSG_RPT_ELS:
  1998. case FC_BSG_HST_ELS_NOLOGIN:
  1999. ret = qla2x00_process_els(bsg_job);
  2000. break;
  2001. case FC_BSG_HST_CT:
  2002. ret = qla2x00_process_ct(bsg_job);
  2003. break;
  2004. case FC_BSG_HST_VENDOR:
  2005. ret = qla2x00_process_vendor_specific(bsg_job);
  2006. break;
  2007. case FC_BSG_HST_ADD_RPORT:
  2008. case FC_BSG_HST_DEL_RPORT:
  2009. case FC_BSG_RPT_CT:
  2010. default:
  2011. DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
  2012. break;
  2013. }
  2014. return ret;
  2015. }
  2016. static int
  2017. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  2018. {
  2019. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  2020. struct qla_hw_data *ha = vha->hw;
  2021. srb_t *sp;
  2022. int cnt, que;
  2023. unsigned long flags;
  2024. struct req_que *req;
  2025. struct srb_bsg *sp_bsg;
  2026. /* find the bsg job from the active list of commands */
  2027. spin_lock_irqsave(&ha->hardware_lock, flags);
  2028. for (que = 0; que < ha->max_req_queues; que++) {
  2029. req = ha->req_q_map[que];
  2030. if (!req)
  2031. continue;
  2032. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++ ) {
  2033. sp = req->outstanding_cmds[cnt];
  2034. if (sp) {
  2035. sp_bsg = (struct srb_bsg*)sp->ctx;
  2036. if (((sp_bsg->ctx.type == SRB_CT_CMD) ||
  2037. (sp_bsg->ctx.type == SRB_ELS_CMD_RPT)
  2038. || ( sp_bsg->ctx.type == SRB_ELS_CMD_HST)) &&
  2039. (sp_bsg->bsg_job == bsg_job)) {
  2040. if (ha->isp_ops->abort_command(sp)) {
  2041. DEBUG2(qla_printk(KERN_INFO, ha,
  2042. "scsi(%ld): mbx abort_command failed\n", vha->host_no));
  2043. bsg_job->req->errors = bsg_job->reply->result = -EIO;
  2044. } else {
  2045. DEBUG2(qla_printk(KERN_INFO, ha,
  2046. "scsi(%ld): mbx abort_command success\n", vha->host_no));
  2047. bsg_job->req->errors = bsg_job->reply->result = 0;
  2048. }
  2049. goto done;
  2050. }
  2051. }
  2052. }
  2053. }
  2054. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2055. DEBUG2(qla_printk(KERN_INFO, ha,
  2056. "scsi(%ld) SRB not found to abort\n", vha->host_no));
  2057. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  2058. return 0;
  2059. done:
  2060. if (bsg_job->request->msgcode == FC_BSG_HST_CT)
  2061. kfree(sp->fcport);
  2062. kfree(sp->ctx);
  2063. mempool_free(sp, ha->srb_mempool);
  2064. return 0;
  2065. }
  2066. struct fc_function_template qla2xxx_transport_functions = {
  2067. .show_host_node_name = 1,
  2068. .show_host_port_name = 1,
  2069. .show_host_supported_classes = 1,
  2070. .show_host_supported_speeds = 1,
  2071. .get_host_port_id = qla2x00_get_host_port_id,
  2072. .show_host_port_id = 1,
  2073. .get_host_speed = qla2x00_get_host_speed,
  2074. .show_host_speed = 1,
  2075. .get_host_port_type = qla2x00_get_host_port_type,
  2076. .show_host_port_type = 1,
  2077. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2078. .show_host_symbolic_name = 1,
  2079. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2080. .show_host_system_hostname = 1,
  2081. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2082. .show_host_fabric_name = 1,
  2083. .get_host_port_state = qla2x00_get_host_port_state,
  2084. .show_host_port_state = 1,
  2085. .dd_fcrport_size = sizeof(struct fc_port *),
  2086. .show_rport_supported_classes = 1,
  2087. .get_starget_node_name = qla2x00_get_starget_node_name,
  2088. .show_starget_node_name = 1,
  2089. .get_starget_port_name = qla2x00_get_starget_port_name,
  2090. .show_starget_port_name = 1,
  2091. .get_starget_port_id = qla2x00_get_starget_port_id,
  2092. .show_starget_port_id = 1,
  2093. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2094. .show_rport_dev_loss_tmo = 1,
  2095. .issue_fc_host_lip = qla2x00_issue_lip,
  2096. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2097. .terminate_rport_io = qla2x00_terminate_rport_io,
  2098. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2099. .vport_create = qla24xx_vport_create,
  2100. .vport_disable = qla24xx_vport_disable,
  2101. .vport_delete = qla24xx_vport_delete,
  2102. .bsg_request = qla24xx_bsg_request,
  2103. .bsg_timeout = qla24xx_bsg_timeout,
  2104. };
  2105. struct fc_function_template qla2xxx_transport_vport_functions = {
  2106. .show_host_node_name = 1,
  2107. .show_host_port_name = 1,
  2108. .show_host_supported_classes = 1,
  2109. .get_host_port_id = qla2x00_get_host_port_id,
  2110. .show_host_port_id = 1,
  2111. .get_host_speed = qla2x00_get_host_speed,
  2112. .show_host_speed = 1,
  2113. .get_host_port_type = qla2x00_get_host_port_type,
  2114. .show_host_port_type = 1,
  2115. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2116. .show_host_symbolic_name = 1,
  2117. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2118. .show_host_system_hostname = 1,
  2119. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2120. .show_host_fabric_name = 1,
  2121. .get_host_port_state = qla2x00_get_host_port_state,
  2122. .show_host_port_state = 1,
  2123. .dd_fcrport_size = sizeof(struct fc_port *),
  2124. .show_rport_supported_classes = 1,
  2125. .get_starget_node_name = qla2x00_get_starget_node_name,
  2126. .show_starget_node_name = 1,
  2127. .get_starget_port_name = qla2x00_get_starget_port_name,
  2128. .show_starget_port_name = 1,
  2129. .get_starget_port_id = qla2x00_get_starget_port_id,
  2130. .show_starget_port_id = 1,
  2131. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2132. .show_rport_dev_loss_tmo = 1,
  2133. .issue_fc_host_lip = qla2x00_issue_lip,
  2134. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2135. .terminate_rport_io = qla2x00_terminate_rport_io,
  2136. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2137. .bsg_request = qla24xx_bsg_request,
  2138. .bsg_timeout = qla24xx_bsg_timeout,
  2139. };
  2140. void
  2141. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  2142. {
  2143. struct qla_hw_data *ha = vha->hw;
  2144. u32 speed = FC_PORTSPEED_UNKNOWN;
  2145. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  2146. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  2147. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  2148. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  2149. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  2150. if (IS_QLA81XX(ha))
  2151. speed = FC_PORTSPEED_10GBIT;
  2152. else if (IS_QLA25XX(ha))
  2153. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  2154. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2155. else if (IS_QLA24XX_TYPE(ha))
  2156. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  2157. FC_PORTSPEED_1GBIT;
  2158. else if (IS_QLA23XX(ha))
  2159. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2160. else
  2161. speed = FC_PORTSPEED_1GBIT;
  2162. fc_host_supported_speeds(vha->host) = speed;
  2163. }
  2164. static int
  2165. qla84xx_reset(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2166. {
  2167. int ret = 0;
  2168. int cmd;
  2169. uint16_t cmd_status;
  2170. DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2171. cmd = (*((bsg_job->request->rqst_data.h_vendor.vendor_cmd) + 2))
  2172. == A84_RESET_FLAG_ENABLE_DIAG_FW ?
  2173. A84_ISSUE_RESET_DIAG_FW : A84_ISSUE_RESET_OP_FW;
  2174. ret = qla84xx_reset_chip(ha, cmd == A84_ISSUE_RESET_DIAG_FW,
  2175. &cmd_status);
  2176. return ret;
  2177. }
  2178. static int
  2179. qla84xx_mgmt_cmd(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2180. {
  2181. struct access_chip_84xx *mn;
  2182. dma_addr_t mn_dma, mgmt_dma;
  2183. void *mgmt_b = NULL;
  2184. int ret = 0;
  2185. int rsp_hdr_len, len = 0;
  2186. struct qla84_msg_mgmt *ql84_mgmt;
  2187. ql84_mgmt = (struct qla84_msg_mgmt *) vmalloc(sizeof(struct qla84_msg_mgmt));
  2188. ql84_mgmt->cmd =
  2189. *((uint16_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 2));
  2190. ql84_mgmt->mgmtp.u.mem.start_addr =
  2191. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 3));
  2192. ql84_mgmt->len =
  2193. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 4));
  2194. ql84_mgmt->mgmtp.u.config.id =
  2195. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 5));
  2196. ql84_mgmt->mgmtp.u.config.param0 =
  2197. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 6));
  2198. ql84_mgmt->mgmtp.u.config.param1 =
  2199. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 7));
  2200. ql84_mgmt->mgmtp.u.info.type =
  2201. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 8));
  2202. ql84_mgmt->mgmtp.u.info.context =
  2203. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 9));
  2204. rsp_hdr_len = bsg_job->request_payload.payload_len;
  2205. mn = dma_pool_alloc(ha->hw->s_dma_pool, GFP_KERNEL, &mn_dma);
  2206. if (mn == NULL) {
  2207. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
  2208. "failed%lu\n", __func__, ha->host_no));
  2209. return -ENOMEM;
  2210. }
  2211. memset(mn, 0, sizeof (struct access_chip_84xx));
  2212. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  2213. mn->entry_count = 1;
  2214. switch (ql84_mgmt->cmd) {
  2215. case QLA84_MGMT_READ_MEM:
  2216. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  2217. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2218. break;
  2219. case QLA84_MGMT_WRITE_MEM:
  2220. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  2221. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2222. break;
  2223. case QLA84_MGMT_CHNG_CONFIG:
  2224. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  2225. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.id);
  2226. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param0);
  2227. mn->parameter3 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param1);
  2228. break;
  2229. case QLA84_MGMT_GET_INFO:
  2230. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  2231. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.type);
  2232. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.context);
  2233. break;
  2234. default:
  2235. ret = -EIO;
  2236. goto exit_mgmt0;
  2237. }
  2238. if ((len == ql84_mgmt->len) &&
  2239. ql84_mgmt->cmd != QLA84_MGMT_CHNG_CONFIG) {
  2240. mgmt_b = dma_alloc_coherent(&ha->hw->pdev->dev, len,
  2241. &mgmt_dma, GFP_KERNEL);
  2242. if (mgmt_b == NULL) {
  2243. DEBUG2(printk(KERN_ERR "%s: dma alloc mgmt_b "
  2244. "failed%lu\n", __func__, ha->host_no));
  2245. ret = -ENOMEM;
  2246. goto exit_mgmt0;
  2247. }
  2248. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->len);
  2249. mn->dseg_count = cpu_to_le16(1);
  2250. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  2251. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  2252. mn->dseg_length = cpu_to_le32(len);
  2253. if (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM) {
  2254. memcpy(mgmt_b, ql84_mgmt->payload, len);
  2255. }
  2256. }
  2257. ret = qla2x00_issue_iocb(ha, mn, mn_dma, 0);
  2258. if ((ret != QLA_SUCCESS) || (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM)
  2259. || (ql84_mgmt->cmd == QLA84_MGMT_CHNG_CONFIG)) {
  2260. if (ret != QLA_SUCCESS)
  2261. DEBUG2(printk(KERN_ERR "%s(%lu): failed\n",
  2262. __func__, ha->host_no));
  2263. } else if ((ql84_mgmt->cmd == QLA84_MGMT_READ_MEM) ||
  2264. (ql84_mgmt->cmd == QLA84_MGMT_GET_INFO)) {
  2265. }
  2266. if (mgmt_b)
  2267. dma_free_coherent(&ha->hw->pdev->dev, len, mgmt_b, mgmt_dma);
  2268. exit_mgmt0:
  2269. dma_pool_free(ha->hw->s_dma_pool, mn, mn_dma);
  2270. return ret;
  2271. }