zfcp_fsf.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2010
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  19. {
  20. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  21. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  22. "fsrth_1", NULL);
  23. }
  24. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  25. unsigned long timeout)
  26. {
  27. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  28. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  29. fsf_req->timer.expires = jiffies + timeout;
  30. add_timer(&fsf_req->timer);
  31. }
  32. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  33. {
  34. BUG_ON(!fsf_req->erp_action);
  35. fsf_req->timer.function = zfcp_erp_timeout_handler;
  36. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  37. fsf_req->timer.expires = jiffies + 30 * HZ;
  38. add_timer(&fsf_req->timer);
  39. }
  40. /* association between FSF command and FSF QTCB type */
  41. static u32 fsf_qtcb_type[] = {
  42. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  43. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  52. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  53. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  54. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  55. };
  56. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  57. {
  58. u16 subtable = table >> 16;
  59. u16 rule = table & 0xffff;
  60. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  61. if (subtable && subtable < ARRAY_SIZE(act_type))
  62. dev_warn(&adapter->ccw_device->dev,
  63. "Access denied according to ACT rule type %s, "
  64. "rule %d\n", act_type[subtable], rule);
  65. }
  66. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  67. struct zfcp_port *port)
  68. {
  69. struct fsf_qtcb_header *header = &req->qtcb->header;
  70. dev_warn(&req->adapter->ccw_device->dev,
  71. "Access denied to port 0x%016Lx\n",
  72. (unsigned long long)port->wwpn);
  73. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  74. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  75. zfcp_erp_port_access_denied(port, "fspad_1", req);
  76. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  77. }
  78. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  79. struct zfcp_unit *unit)
  80. {
  81. struct fsf_qtcb_header *header = &req->qtcb->header;
  82. dev_warn(&req->adapter->ccw_device->dev,
  83. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  84. (unsigned long long)unit->fcp_lun,
  85. (unsigned long long)unit->port->wwpn);
  86. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  87. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  88. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  89. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  90. }
  91. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  92. {
  93. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  94. "operational because of an unsupported FC class\n");
  95. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  96. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  97. }
  98. /**
  99. * zfcp_fsf_req_free - free memory used by fsf request
  100. * @fsf_req: pointer to struct zfcp_fsf_req
  101. */
  102. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  103. {
  104. if (likely(req->pool)) {
  105. if (likely(req->qtcb))
  106. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  107. mempool_free(req, req->pool);
  108. return;
  109. }
  110. if (likely(req->qtcb))
  111. kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
  112. kfree(req);
  113. }
  114. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  115. {
  116. unsigned long flags;
  117. struct fsf_status_read_buffer *sr_buf = req->data;
  118. struct zfcp_adapter *adapter = req->adapter;
  119. struct zfcp_port *port;
  120. int d_id = ntoh24(sr_buf->d_id);
  121. read_lock_irqsave(&adapter->port_list_lock, flags);
  122. list_for_each_entry(port, &adapter->port_list, list)
  123. if (port->d_id == d_id) {
  124. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  125. break;
  126. }
  127. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  128. }
  129. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  130. struct fsf_link_down_info *link_down)
  131. {
  132. struct zfcp_adapter *adapter = req->adapter;
  133. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  134. return;
  135. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  136. zfcp_scsi_schedule_rports_block(adapter);
  137. if (!link_down)
  138. goto out;
  139. switch (link_down->error_code) {
  140. case FSF_PSQ_LINK_NO_LIGHT:
  141. dev_warn(&req->adapter->ccw_device->dev,
  142. "There is no light signal from the local "
  143. "fibre channel cable\n");
  144. break;
  145. case FSF_PSQ_LINK_WRAP_PLUG:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "There is a wrap plug instead of a fibre "
  148. "channel cable\n");
  149. break;
  150. case FSF_PSQ_LINK_NO_FCP:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The adjacent fibre channel node does not "
  153. "support FCP\n");
  154. break;
  155. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The FCP device is suspended because of a "
  158. "firmware update\n");
  159. break;
  160. case FSF_PSQ_LINK_INVALID_WWPN:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "The FCP device detected a WWPN that is "
  163. "duplicate or not valid\n");
  164. break;
  165. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "The fibre channel fabric does not support NPIV\n");
  168. break;
  169. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  170. dev_warn(&req->adapter->ccw_device->dev,
  171. "The FCP adapter cannot support more NPIV ports\n");
  172. break;
  173. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  174. dev_warn(&req->adapter->ccw_device->dev,
  175. "The adjacent switch cannot support "
  176. "more NPIV ports\n");
  177. break;
  178. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  179. dev_warn(&req->adapter->ccw_device->dev,
  180. "The FCP adapter could not log in to the "
  181. "fibre channel fabric\n");
  182. break;
  183. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  184. dev_warn(&req->adapter->ccw_device->dev,
  185. "The WWPN assignment file on the FCP adapter "
  186. "has been damaged\n");
  187. break;
  188. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  189. dev_warn(&req->adapter->ccw_device->dev,
  190. "The mode table on the FCP adapter "
  191. "has been damaged\n");
  192. break;
  193. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  194. dev_warn(&req->adapter->ccw_device->dev,
  195. "All NPIV ports on the FCP adapter have "
  196. "been assigned\n");
  197. break;
  198. default:
  199. dev_warn(&req->adapter->ccw_device->dev,
  200. "The link between the FCP adapter and "
  201. "the FC fabric is down\n");
  202. }
  203. out:
  204. zfcp_erp_adapter_failed(adapter, id, req);
  205. }
  206. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  207. {
  208. struct fsf_status_read_buffer *sr_buf = req->data;
  209. struct fsf_link_down_info *ldi =
  210. (struct fsf_link_down_info *) &sr_buf->payload;
  211. switch (sr_buf->status_subtype) {
  212. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  213. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  214. break;
  215. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  216. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  217. break;
  218. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  219. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  220. };
  221. }
  222. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  223. {
  224. struct zfcp_adapter *adapter = req->adapter;
  225. struct fsf_status_read_buffer *sr_buf = req->data;
  226. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  227. zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
  228. mempool_free(sr_buf, adapter->pool.status_read_data);
  229. zfcp_fsf_req_free(req);
  230. return;
  231. }
  232. zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
  233. switch (sr_buf->status_type) {
  234. case FSF_STATUS_READ_PORT_CLOSED:
  235. zfcp_fsf_status_read_port_closed(req);
  236. break;
  237. case FSF_STATUS_READ_INCOMING_ELS:
  238. zfcp_fc_incoming_els(req);
  239. break;
  240. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  241. break;
  242. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  243. dev_warn(&adapter->ccw_device->dev,
  244. "The error threshold for checksum statistics "
  245. "has been exceeded\n");
  246. zfcp_dbf_hba_berr(adapter->dbf, req);
  247. break;
  248. case FSF_STATUS_READ_LINK_DOWN:
  249. zfcp_fsf_status_read_link_down(req);
  250. break;
  251. case FSF_STATUS_READ_LINK_UP:
  252. dev_info(&adapter->ccw_device->dev,
  253. "The local link has been restored\n");
  254. /* All ports should be marked as ready to run again */
  255. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  256. ZFCP_STATUS_COMMON_RUNNING,
  257. ZFCP_SET);
  258. zfcp_erp_adapter_reopen(adapter,
  259. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  260. ZFCP_STATUS_COMMON_ERP_FAILED,
  261. "fssrh_2", req);
  262. break;
  263. case FSF_STATUS_READ_NOTIFICATION_LOST:
  264. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  265. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  266. req);
  267. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  268. queue_work(adapter->work_queue, &adapter->scan_work);
  269. break;
  270. case FSF_STATUS_READ_CFDC_UPDATED:
  271. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  272. break;
  273. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  274. adapter->adapter_features = sr_buf->payload.word[0];
  275. break;
  276. }
  277. mempool_free(sr_buf, adapter->pool.status_read_data);
  278. zfcp_fsf_req_free(req);
  279. atomic_inc(&adapter->stat_miss);
  280. queue_work(adapter->work_queue, &adapter->stat_work);
  281. }
  282. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  283. {
  284. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  285. case FSF_SQ_FCP_RSP_AVAILABLE:
  286. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  287. case FSF_SQ_NO_RETRY_POSSIBLE:
  288. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  289. return;
  290. case FSF_SQ_COMMAND_ABORTED:
  291. break;
  292. case FSF_SQ_NO_RECOM:
  293. dev_err(&req->adapter->ccw_device->dev,
  294. "The FCP adapter reported a problem "
  295. "that cannot be recovered\n");
  296. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  297. break;
  298. }
  299. /* all non-return stats set FSFREQ_ERROR*/
  300. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  301. }
  302. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  303. {
  304. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  305. return;
  306. switch (req->qtcb->header.fsf_status) {
  307. case FSF_UNKNOWN_COMMAND:
  308. dev_err(&req->adapter->ccw_device->dev,
  309. "The FCP adapter does not recognize the command 0x%x\n",
  310. req->qtcb->header.fsf_command);
  311. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  312. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  313. break;
  314. case FSF_ADAPTER_STATUS_AVAILABLE:
  315. zfcp_fsf_fsfstatus_qual_eval(req);
  316. break;
  317. }
  318. }
  319. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  320. {
  321. struct zfcp_adapter *adapter = req->adapter;
  322. struct fsf_qtcb *qtcb = req->qtcb;
  323. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  324. zfcp_dbf_hba_fsf_response(req);
  325. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  326. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  327. return;
  328. }
  329. switch (qtcb->prefix.prot_status) {
  330. case FSF_PROT_GOOD:
  331. case FSF_PROT_FSF_STATUS_PRESENTED:
  332. return;
  333. case FSF_PROT_QTCB_VERSION_ERROR:
  334. dev_err(&adapter->ccw_device->dev,
  335. "QTCB version 0x%x not supported by FCP adapter "
  336. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  337. psq->word[0], psq->word[1]);
  338. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  339. break;
  340. case FSF_PROT_ERROR_STATE:
  341. case FSF_PROT_SEQ_NUMB_ERROR:
  342. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  343. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  344. break;
  345. case FSF_PROT_UNSUPP_QTCB_TYPE:
  346. dev_err(&adapter->ccw_device->dev,
  347. "The QTCB type is not supported by the FCP adapter\n");
  348. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  349. break;
  350. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  351. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  352. &adapter->status);
  353. break;
  354. case FSF_PROT_DUPLICATE_REQUEST_ID:
  355. dev_err(&adapter->ccw_device->dev,
  356. "0x%Lx is an ambiguous request identifier\n",
  357. (unsigned long long)qtcb->bottom.support.req_handle);
  358. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  359. break;
  360. case FSF_PROT_LINK_DOWN:
  361. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  362. &psq->link_down_info);
  363. /* go through reopen to flush pending requests */
  364. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  365. break;
  366. case FSF_PROT_REEST_QUEUE:
  367. /* All ports should be marked as ready to run again */
  368. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  369. ZFCP_STATUS_COMMON_RUNNING,
  370. ZFCP_SET);
  371. zfcp_erp_adapter_reopen(adapter,
  372. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  373. ZFCP_STATUS_COMMON_ERP_FAILED,
  374. "fspse_8", req);
  375. break;
  376. default:
  377. dev_err(&adapter->ccw_device->dev,
  378. "0x%x is not a valid transfer protocol status\n",
  379. qtcb->prefix.prot_status);
  380. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  381. }
  382. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  383. }
  384. /**
  385. * zfcp_fsf_req_complete - process completion of a FSF request
  386. * @fsf_req: The FSF request that has been completed.
  387. *
  388. * When a request has been completed either from the FCP adapter,
  389. * or it has been dismissed due to a queue shutdown, this function
  390. * is called to process the completion status and trigger further
  391. * events related to the FSF request.
  392. */
  393. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  394. {
  395. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  396. zfcp_fsf_status_read_handler(req);
  397. return;
  398. }
  399. del_timer(&req->timer);
  400. zfcp_fsf_protstatus_eval(req);
  401. zfcp_fsf_fsfstatus_eval(req);
  402. req->handler(req);
  403. if (req->erp_action)
  404. zfcp_erp_notify(req->erp_action, 0);
  405. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  406. zfcp_fsf_req_free(req);
  407. else
  408. complete(&req->completion);
  409. }
  410. /**
  411. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  412. * @adapter: pointer to struct zfcp_adapter
  413. *
  414. * Never ever call this without shutting down the adapter first.
  415. * Otherwise the adapter would continue using and corrupting s390 storage.
  416. * Included BUG_ON() call to ensure this is done.
  417. * ERP is supposed to be the only user of this function.
  418. */
  419. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  420. {
  421. struct zfcp_fsf_req *req, *tmp;
  422. LIST_HEAD(remove_queue);
  423. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  424. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  425. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  426. list_del(&req->list);
  427. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  428. zfcp_fsf_req_complete(req);
  429. }
  430. }
  431. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  432. {
  433. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  434. struct zfcp_adapter *adapter = req->adapter;
  435. struct Scsi_Host *shost = adapter->scsi_host;
  436. struct fc_els_flogi *nsp, *plogi;
  437. /* adjust pointers for missing command code */
  438. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  439. - sizeof(u32));
  440. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  441. - sizeof(u32));
  442. if (req->data)
  443. memcpy(req->data, bottom, sizeof(*bottom));
  444. fc_host_port_name(shost) = nsp->fl_wwpn;
  445. fc_host_node_name(shost) = nsp->fl_wwnn;
  446. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  447. fc_host_speed(shost) = bottom->fc_link_speed;
  448. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  449. adapter->hydra_version = bottom->adapter_type;
  450. adapter->timer_ticks = bottom->timer_interval;
  451. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  452. (u16)FSF_STATUS_READS_RECOM);
  453. if (fc_host_permanent_port_name(shost) == -1)
  454. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  455. switch (bottom->fc_topology) {
  456. case FSF_TOPO_P2P:
  457. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  458. adapter->peer_wwpn = plogi->fl_wwpn;
  459. adapter->peer_wwnn = plogi->fl_wwnn;
  460. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  461. break;
  462. case FSF_TOPO_FABRIC:
  463. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  464. break;
  465. case FSF_TOPO_AL:
  466. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  467. /* fall through */
  468. default:
  469. dev_err(&adapter->ccw_device->dev,
  470. "Unknown or unsupported arbitrated loop "
  471. "fibre channel topology detected\n");
  472. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  473. return -EIO;
  474. }
  475. return 0;
  476. }
  477. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  478. {
  479. struct zfcp_adapter *adapter = req->adapter;
  480. struct fsf_qtcb *qtcb = req->qtcb;
  481. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  482. struct Scsi_Host *shost = adapter->scsi_host;
  483. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  484. return;
  485. adapter->fsf_lic_version = bottom->lic_version;
  486. adapter->adapter_features = bottom->adapter_features;
  487. adapter->connection_features = bottom->connection_features;
  488. adapter->peer_wwpn = 0;
  489. adapter->peer_wwnn = 0;
  490. adapter->peer_d_id = 0;
  491. switch (qtcb->header.fsf_status) {
  492. case FSF_GOOD:
  493. if (zfcp_fsf_exchange_config_evaluate(req))
  494. return;
  495. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  496. dev_err(&adapter->ccw_device->dev,
  497. "FCP adapter maximum QTCB size (%d bytes) "
  498. "is too small\n",
  499. bottom->max_qtcb_size);
  500. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  501. return;
  502. }
  503. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  504. &adapter->status);
  505. break;
  506. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  507. fc_host_node_name(shost) = 0;
  508. fc_host_port_name(shost) = 0;
  509. fc_host_port_id(shost) = 0;
  510. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  511. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  512. adapter->hydra_version = 0;
  513. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  514. &adapter->status);
  515. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  516. &qtcb->header.fsf_status_qual.link_down_info);
  517. break;
  518. default:
  519. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  520. return;
  521. }
  522. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  523. adapter->hardware_version = bottom->hardware_version;
  524. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  525. min(FC_SERIAL_NUMBER_SIZE, 17));
  526. EBCASC(fc_host_serial_number(shost),
  527. min(FC_SERIAL_NUMBER_SIZE, 17));
  528. }
  529. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  530. dev_err(&adapter->ccw_device->dev,
  531. "The FCP adapter only supports newer "
  532. "control block versions\n");
  533. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  534. return;
  535. }
  536. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  537. dev_err(&adapter->ccw_device->dev,
  538. "The FCP adapter only supports older "
  539. "control block versions\n");
  540. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  541. }
  542. }
  543. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  544. {
  545. struct zfcp_adapter *adapter = req->adapter;
  546. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  547. struct Scsi_Host *shost = adapter->scsi_host;
  548. if (req->data)
  549. memcpy(req->data, bottom, sizeof(*bottom));
  550. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  551. fc_host_permanent_port_name(shost) = bottom->wwpn;
  552. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  553. } else
  554. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  555. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  556. fc_host_supported_speeds(shost) = bottom->supported_speed;
  557. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  558. FC_FC4_LIST_SIZE);
  559. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  560. FC_FC4_LIST_SIZE);
  561. }
  562. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  563. {
  564. struct fsf_qtcb *qtcb = req->qtcb;
  565. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  566. return;
  567. switch (qtcb->header.fsf_status) {
  568. case FSF_GOOD:
  569. zfcp_fsf_exchange_port_evaluate(req);
  570. break;
  571. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  572. zfcp_fsf_exchange_port_evaluate(req);
  573. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  574. &qtcb->header.fsf_status_qual.link_down_info);
  575. break;
  576. }
  577. }
  578. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  579. {
  580. struct zfcp_fsf_req *req;
  581. if (likely(pool))
  582. req = mempool_alloc(pool, GFP_ATOMIC);
  583. else
  584. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  585. if (unlikely(!req))
  586. return NULL;
  587. memset(req, 0, sizeof(*req));
  588. req->pool = pool;
  589. return req;
  590. }
  591. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  592. {
  593. struct fsf_qtcb *qtcb;
  594. if (likely(pool))
  595. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  596. else
  597. qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
  598. if (unlikely(!qtcb))
  599. return NULL;
  600. memset(qtcb, 0, sizeof(*qtcb));
  601. return qtcb;
  602. }
  603. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  604. u32 fsf_cmd, u32 sbtype,
  605. mempool_t *pool)
  606. {
  607. struct zfcp_adapter *adapter = qdio->adapter;
  608. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  609. if (unlikely(!req))
  610. return ERR_PTR(-ENOMEM);
  611. if (adapter->req_no == 0)
  612. adapter->req_no++;
  613. INIT_LIST_HEAD(&req->list);
  614. init_timer(&req->timer);
  615. init_completion(&req->completion);
  616. req->adapter = adapter;
  617. req->fsf_command = fsf_cmd;
  618. req->req_id = adapter->req_no;
  619. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  620. if (likely(pool))
  621. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  622. else
  623. req->qtcb = zfcp_qtcb_alloc(NULL);
  624. if (unlikely(!req->qtcb)) {
  625. zfcp_fsf_req_free(req);
  626. return ERR_PTR(-ENOMEM);
  627. }
  628. req->seq_no = adapter->fsf_req_seq_no;
  629. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  630. req->qtcb->prefix.req_id = req->req_id;
  631. req->qtcb->prefix.ulp_info = 26;
  632. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  633. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  634. req->qtcb->header.req_handle = req->req_id;
  635. req->qtcb->header.fsf_command = req->fsf_command;
  636. }
  637. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  638. req->qtcb, sizeof(struct fsf_qtcb));
  639. return req;
  640. }
  641. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  642. {
  643. struct zfcp_adapter *adapter = req->adapter;
  644. struct zfcp_qdio *qdio = adapter->qdio;
  645. int with_qtcb = (req->qtcb != NULL);
  646. int req_id = req->req_id;
  647. zfcp_reqlist_add(adapter->req_list, req);
  648. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
  649. req->issued = get_clock();
  650. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  651. del_timer(&req->timer);
  652. /* lookup request again, list might have changed */
  653. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  654. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  655. return -EIO;
  656. }
  657. /* Don't increase for unsolicited status */
  658. if (with_qtcb)
  659. adapter->fsf_req_seq_no++;
  660. adapter->req_no++;
  661. return 0;
  662. }
  663. /**
  664. * zfcp_fsf_status_read - send status read request
  665. * @adapter: pointer to struct zfcp_adapter
  666. * @req_flags: request flags
  667. * Returns: 0 on success, ERROR otherwise
  668. */
  669. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  670. {
  671. struct zfcp_adapter *adapter = qdio->adapter;
  672. struct zfcp_fsf_req *req;
  673. struct fsf_status_read_buffer *sr_buf;
  674. int retval = -EIO;
  675. spin_lock_bh(&qdio->req_q_lock);
  676. if (zfcp_qdio_sbal_get(qdio))
  677. goto out;
  678. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
  679. adapter->pool.status_read_req);
  680. if (IS_ERR(req)) {
  681. retval = PTR_ERR(req);
  682. goto out;
  683. }
  684. sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
  685. if (!sr_buf) {
  686. retval = -ENOMEM;
  687. goto failed_buf;
  688. }
  689. memset(sr_buf, 0, sizeof(*sr_buf));
  690. req->data = sr_buf;
  691. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  692. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  693. retval = zfcp_fsf_req_send(req);
  694. if (retval)
  695. goto failed_req_send;
  696. goto out;
  697. failed_req_send:
  698. mempool_free(sr_buf, adapter->pool.status_read_data);
  699. failed_buf:
  700. zfcp_fsf_req_free(req);
  701. zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
  702. out:
  703. spin_unlock_bh(&qdio->req_q_lock);
  704. return retval;
  705. }
  706. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  707. {
  708. struct zfcp_unit *unit = req->data;
  709. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  710. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  711. return;
  712. switch (req->qtcb->header.fsf_status) {
  713. case FSF_PORT_HANDLE_NOT_VALID:
  714. if (fsq->word[0] == fsq->word[1]) {
  715. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  716. "fsafch1", req);
  717. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  718. }
  719. break;
  720. case FSF_LUN_HANDLE_NOT_VALID:
  721. if (fsq->word[0] == fsq->word[1]) {
  722. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  723. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  724. }
  725. break;
  726. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  727. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  728. break;
  729. case FSF_PORT_BOXED:
  730. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  731. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  732. break;
  733. case FSF_LUN_BOXED:
  734. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  735. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  736. break;
  737. case FSF_ADAPTER_STATUS_AVAILABLE:
  738. switch (fsq->word[0]) {
  739. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  740. zfcp_fc_test_link(unit->port);
  741. /* fall through */
  742. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  743. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  744. break;
  745. }
  746. break;
  747. case FSF_GOOD:
  748. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  749. break;
  750. }
  751. }
  752. /**
  753. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  754. * @old_req_id: unsigned long
  755. * @unit: pointer to struct zfcp_unit
  756. * Returns: pointer to struct zfcp_fsf_req
  757. */
  758. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  759. struct zfcp_unit *unit)
  760. {
  761. struct zfcp_fsf_req *req = NULL;
  762. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  763. spin_lock_bh(&qdio->req_q_lock);
  764. if (zfcp_qdio_sbal_get(qdio))
  765. goto out;
  766. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  767. SBAL_FLAGS0_TYPE_READ,
  768. qdio->adapter->pool.scsi_abort);
  769. if (IS_ERR(req)) {
  770. req = NULL;
  771. goto out;
  772. }
  773. if (unlikely(!(atomic_read(&unit->status) &
  774. ZFCP_STATUS_COMMON_UNBLOCKED)))
  775. goto out_error_free;
  776. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  777. req->data = unit;
  778. req->handler = zfcp_fsf_abort_fcp_command_handler;
  779. req->qtcb->header.lun_handle = unit->handle;
  780. req->qtcb->header.port_handle = unit->port->handle;
  781. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  782. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  783. if (!zfcp_fsf_req_send(req))
  784. goto out;
  785. out_error_free:
  786. zfcp_fsf_req_free(req);
  787. req = NULL;
  788. out:
  789. spin_unlock_bh(&qdio->req_q_lock);
  790. return req;
  791. }
  792. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  793. {
  794. struct zfcp_adapter *adapter = req->adapter;
  795. struct zfcp_fsf_ct_els *ct = req->data;
  796. struct fsf_qtcb_header *header = &req->qtcb->header;
  797. ct->status = -EINVAL;
  798. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  799. goto skip_fsfstatus;
  800. switch (header->fsf_status) {
  801. case FSF_GOOD:
  802. zfcp_dbf_san_ct_response(req);
  803. ct->status = 0;
  804. break;
  805. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  806. zfcp_fsf_class_not_supp(req);
  807. break;
  808. case FSF_ADAPTER_STATUS_AVAILABLE:
  809. switch (header->fsf_status_qual.word[0]){
  810. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  811. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  812. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  813. break;
  814. }
  815. break;
  816. case FSF_ACCESS_DENIED:
  817. break;
  818. case FSF_PORT_BOXED:
  819. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  820. break;
  821. case FSF_PORT_HANDLE_NOT_VALID:
  822. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  823. /* fall through */
  824. case FSF_GENERIC_COMMAND_REJECTED:
  825. case FSF_PAYLOAD_SIZE_MISMATCH:
  826. case FSF_REQUEST_SIZE_TOO_LARGE:
  827. case FSF_RESPONSE_SIZE_TOO_LARGE:
  828. case FSF_SBAL_MISMATCH:
  829. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  830. break;
  831. }
  832. skip_fsfstatus:
  833. if (ct->handler)
  834. ct->handler(ct->handler_data);
  835. }
  836. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  837. struct zfcp_qdio_req *q_req,
  838. struct scatterlist *sg_req,
  839. struct scatterlist *sg_resp)
  840. {
  841. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  842. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  843. zfcp_qdio_set_sbale_last(qdio, q_req);
  844. }
  845. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  846. struct scatterlist *sg_req,
  847. struct scatterlist *sg_resp,
  848. int max_sbals)
  849. {
  850. struct zfcp_adapter *adapter = req->adapter;
  851. u32 feat = adapter->adapter_features;
  852. int bytes;
  853. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  854. if (!zfcp_qdio_sg_one_sbale(sg_req) ||
  855. !zfcp_qdio_sg_one_sbale(sg_resp))
  856. return -EOPNOTSUPP;
  857. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  858. sg_req, sg_resp);
  859. return 0;
  860. }
  861. /* use single, unchained SBAL if it can hold the request */
  862. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  863. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  864. sg_req, sg_resp);
  865. return 0;
  866. }
  867. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  868. sg_req, max_sbals);
  869. if (bytes <= 0)
  870. return -EIO;
  871. req->qtcb->bottom.support.req_buf_length = bytes;
  872. zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
  873. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  874. sg_resp, max_sbals);
  875. req->qtcb->bottom.support.resp_buf_length = bytes;
  876. if (bytes <= 0)
  877. return -EIO;
  878. return 0;
  879. }
  880. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  881. struct scatterlist *sg_req,
  882. struct scatterlist *sg_resp,
  883. int max_sbals, unsigned int timeout)
  884. {
  885. int ret;
  886. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
  887. if (ret)
  888. return ret;
  889. /* common settings for ct/gs and els requests */
  890. if (timeout > 255)
  891. timeout = 255; /* max value accepted by hardware */
  892. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  893. req->qtcb->bottom.support.timeout = timeout;
  894. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  895. return 0;
  896. }
  897. /**
  898. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  899. * @ct: pointer to struct zfcp_send_ct with data for request
  900. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  901. */
  902. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  903. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  904. unsigned int timeout)
  905. {
  906. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  907. struct zfcp_fsf_req *req;
  908. int ret = -EIO;
  909. spin_lock_bh(&qdio->req_q_lock);
  910. if (zfcp_qdio_sbal_get(qdio))
  911. goto out;
  912. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  913. SBAL_FLAGS0_TYPE_WRITE_READ, pool);
  914. if (IS_ERR(req)) {
  915. ret = PTR_ERR(req);
  916. goto out;
  917. }
  918. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  919. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
  920. ZFCP_FSF_MAX_SBALS_PER_REQ, timeout);
  921. if (ret)
  922. goto failed_send;
  923. req->handler = zfcp_fsf_send_ct_handler;
  924. req->qtcb->header.port_handle = wka_port->handle;
  925. req->data = ct;
  926. zfcp_dbf_san_ct_request(req, wka_port->d_id);
  927. ret = zfcp_fsf_req_send(req);
  928. if (ret)
  929. goto failed_send;
  930. goto out;
  931. failed_send:
  932. zfcp_fsf_req_free(req);
  933. out:
  934. spin_unlock_bh(&qdio->req_q_lock);
  935. return ret;
  936. }
  937. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  938. {
  939. struct zfcp_fsf_ct_els *send_els = req->data;
  940. struct zfcp_port *port = send_els->port;
  941. struct fsf_qtcb_header *header = &req->qtcb->header;
  942. send_els->status = -EINVAL;
  943. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  944. goto skip_fsfstatus;
  945. switch (header->fsf_status) {
  946. case FSF_GOOD:
  947. zfcp_dbf_san_els_response(req);
  948. send_els->status = 0;
  949. break;
  950. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  951. zfcp_fsf_class_not_supp(req);
  952. break;
  953. case FSF_ADAPTER_STATUS_AVAILABLE:
  954. switch (header->fsf_status_qual.word[0]){
  955. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  956. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  957. case FSF_SQ_RETRY_IF_POSSIBLE:
  958. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  959. break;
  960. }
  961. break;
  962. case FSF_ELS_COMMAND_REJECTED:
  963. case FSF_PAYLOAD_SIZE_MISMATCH:
  964. case FSF_REQUEST_SIZE_TOO_LARGE:
  965. case FSF_RESPONSE_SIZE_TOO_LARGE:
  966. break;
  967. case FSF_ACCESS_DENIED:
  968. if (port)
  969. zfcp_fsf_access_denied_port(req, port);
  970. break;
  971. case FSF_SBAL_MISMATCH:
  972. /* should never occure, avoided in zfcp_fsf_send_els */
  973. /* fall through */
  974. default:
  975. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  976. break;
  977. }
  978. skip_fsfstatus:
  979. if (send_els->handler)
  980. send_els->handler(send_els->handler_data);
  981. }
  982. /**
  983. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  984. * @els: pointer to struct zfcp_send_els with data for the command
  985. */
  986. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  987. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  988. {
  989. struct zfcp_fsf_req *req;
  990. struct zfcp_qdio *qdio = adapter->qdio;
  991. int ret = -EIO;
  992. spin_lock_bh(&qdio->req_q_lock);
  993. if (zfcp_qdio_sbal_get(qdio))
  994. goto out;
  995. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  996. SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
  997. if (IS_ERR(req)) {
  998. ret = PTR_ERR(req);
  999. goto out;
  1000. }
  1001. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1002. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
  1003. if (ret)
  1004. goto failed_send;
  1005. hton24(req->qtcb->bottom.support.d_id, d_id);
  1006. req->handler = zfcp_fsf_send_els_handler;
  1007. req->data = els;
  1008. zfcp_dbf_san_els_request(req);
  1009. ret = zfcp_fsf_req_send(req);
  1010. if (ret)
  1011. goto failed_send;
  1012. goto out;
  1013. failed_send:
  1014. zfcp_fsf_req_free(req);
  1015. out:
  1016. spin_unlock_bh(&qdio->req_q_lock);
  1017. return ret;
  1018. }
  1019. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1020. {
  1021. struct zfcp_fsf_req *req;
  1022. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1023. int retval = -EIO;
  1024. spin_lock_bh(&qdio->req_q_lock);
  1025. if (zfcp_qdio_sbal_get(qdio))
  1026. goto out;
  1027. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1028. SBAL_FLAGS0_TYPE_READ,
  1029. qdio->adapter->pool.erp_req);
  1030. if (IS_ERR(req)) {
  1031. retval = PTR_ERR(req);
  1032. goto out;
  1033. }
  1034. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1035. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1036. req->qtcb->bottom.config.feature_selection =
  1037. FSF_FEATURE_CFDC |
  1038. FSF_FEATURE_LUN_SHARING |
  1039. FSF_FEATURE_NOTIFICATION_LOST |
  1040. FSF_FEATURE_UPDATE_ALERT;
  1041. req->erp_action = erp_action;
  1042. req->handler = zfcp_fsf_exchange_config_data_handler;
  1043. erp_action->fsf_req_id = req->req_id;
  1044. zfcp_fsf_start_erp_timer(req);
  1045. retval = zfcp_fsf_req_send(req);
  1046. if (retval) {
  1047. zfcp_fsf_req_free(req);
  1048. erp_action->fsf_req_id = 0;
  1049. }
  1050. out:
  1051. spin_unlock_bh(&qdio->req_q_lock);
  1052. return retval;
  1053. }
  1054. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1055. struct fsf_qtcb_bottom_config *data)
  1056. {
  1057. struct zfcp_fsf_req *req = NULL;
  1058. int retval = -EIO;
  1059. spin_lock_bh(&qdio->req_q_lock);
  1060. if (zfcp_qdio_sbal_get(qdio))
  1061. goto out_unlock;
  1062. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1063. SBAL_FLAGS0_TYPE_READ, NULL);
  1064. if (IS_ERR(req)) {
  1065. retval = PTR_ERR(req);
  1066. goto out_unlock;
  1067. }
  1068. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1069. req->handler = zfcp_fsf_exchange_config_data_handler;
  1070. req->qtcb->bottom.config.feature_selection =
  1071. FSF_FEATURE_CFDC |
  1072. FSF_FEATURE_LUN_SHARING |
  1073. FSF_FEATURE_NOTIFICATION_LOST |
  1074. FSF_FEATURE_UPDATE_ALERT;
  1075. if (data)
  1076. req->data = data;
  1077. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1078. retval = zfcp_fsf_req_send(req);
  1079. spin_unlock_bh(&qdio->req_q_lock);
  1080. if (!retval)
  1081. wait_for_completion(&req->completion);
  1082. zfcp_fsf_req_free(req);
  1083. return retval;
  1084. out_unlock:
  1085. spin_unlock_bh(&qdio->req_q_lock);
  1086. return retval;
  1087. }
  1088. /**
  1089. * zfcp_fsf_exchange_port_data - request information about local port
  1090. * @erp_action: ERP action for the adapter for which port data is requested
  1091. * Returns: 0 on success, error otherwise
  1092. */
  1093. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1094. {
  1095. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1096. struct zfcp_fsf_req *req;
  1097. int retval = -EIO;
  1098. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1099. return -EOPNOTSUPP;
  1100. spin_lock_bh(&qdio->req_q_lock);
  1101. if (zfcp_qdio_sbal_get(qdio))
  1102. goto out;
  1103. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1104. SBAL_FLAGS0_TYPE_READ,
  1105. qdio->adapter->pool.erp_req);
  1106. if (IS_ERR(req)) {
  1107. retval = PTR_ERR(req);
  1108. goto out;
  1109. }
  1110. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1111. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1112. req->handler = zfcp_fsf_exchange_port_data_handler;
  1113. req->erp_action = erp_action;
  1114. erp_action->fsf_req_id = req->req_id;
  1115. zfcp_fsf_start_erp_timer(req);
  1116. retval = zfcp_fsf_req_send(req);
  1117. if (retval) {
  1118. zfcp_fsf_req_free(req);
  1119. erp_action->fsf_req_id = 0;
  1120. }
  1121. out:
  1122. spin_unlock_bh(&qdio->req_q_lock);
  1123. return retval;
  1124. }
  1125. /**
  1126. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1127. * @qdio: pointer to struct zfcp_qdio
  1128. * @data: pointer to struct fsf_qtcb_bottom_port
  1129. * Returns: 0 on success, error otherwise
  1130. */
  1131. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1132. struct fsf_qtcb_bottom_port *data)
  1133. {
  1134. struct zfcp_fsf_req *req = NULL;
  1135. int retval = -EIO;
  1136. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1137. return -EOPNOTSUPP;
  1138. spin_lock_bh(&qdio->req_q_lock);
  1139. if (zfcp_qdio_sbal_get(qdio))
  1140. goto out_unlock;
  1141. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1142. SBAL_FLAGS0_TYPE_READ, NULL);
  1143. if (IS_ERR(req)) {
  1144. retval = PTR_ERR(req);
  1145. goto out_unlock;
  1146. }
  1147. if (data)
  1148. req->data = data;
  1149. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1150. req->handler = zfcp_fsf_exchange_port_data_handler;
  1151. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1152. retval = zfcp_fsf_req_send(req);
  1153. spin_unlock_bh(&qdio->req_q_lock);
  1154. if (!retval)
  1155. wait_for_completion(&req->completion);
  1156. zfcp_fsf_req_free(req);
  1157. return retval;
  1158. out_unlock:
  1159. spin_unlock_bh(&qdio->req_q_lock);
  1160. return retval;
  1161. }
  1162. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1163. {
  1164. struct zfcp_port *port = req->data;
  1165. struct fsf_qtcb_header *header = &req->qtcb->header;
  1166. struct fc_els_flogi *plogi;
  1167. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1168. goto out;
  1169. switch (header->fsf_status) {
  1170. case FSF_PORT_ALREADY_OPEN:
  1171. break;
  1172. case FSF_ACCESS_DENIED:
  1173. zfcp_fsf_access_denied_port(req, port);
  1174. break;
  1175. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1176. dev_warn(&req->adapter->ccw_device->dev,
  1177. "Not enough FCP adapter resources to open "
  1178. "remote port 0x%016Lx\n",
  1179. (unsigned long long)port->wwpn);
  1180. zfcp_erp_port_failed(port, "fsoph_1", req);
  1181. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1182. break;
  1183. case FSF_ADAPTER_STATUS_AVAILABLE:
  1184. switch (header->fsf_status_qual.word[0]) {
  1185. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1186. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1187. case FSF_SQ_NO_RETRY_POSSIBLE:
  1188. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1189. break;
  1190. }
  1191. break;
  1192. case FSF_GOOD:
  1193. port->handle = header->port_handle;
  1194. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1195. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1196. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1197. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1198. &port->status);
  1199. /* check whether D_ID has changed during open */
  1200. /*
  1201. * FIXME: This check is not airtight, as the FCP channel does
  1202. * not monitor closures of target port connections caused on
  1203. * the remote side. Thus, they might miss out on invalidating
  1204. * locally cached WWPNs (and other N_Port parameters) of gone
  1205. * target ports. So, our heroic attempt to make things safe
  1206. * could be undermined by 'open port' response data tagged with
  1207. * obsolete WWPNs. Another reason to monitor potential
  1208. * connection closures ourself at least (by interpreting
  1209. * incoming ELS' and unsolicited status). It just crosses my
  1210. * mind that one should be able to cross-check by means of
  1211. * another GID_PN straight after a port has been opened.
  1212. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1213. */
  1214. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1215. if (req->qtcb->bottom.support.els1_length >=
  1216. FSF_PLOGI_MIN_LEN)
  1217. zfcp_fc_plogi_evaluate(port, plogi);
  1218. break;
  1219. case FSF_UNKNOWN_OP_SUBTYPE:
  1220. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1221. break;
  1222. }
  1223. out:
  1224. put_device(&port->dev);
  1225. }
  1226. /**
  1227. * zfcp_fsf_open_port - create and send open port request
  1228. * @erp_action: pointer to struct zfcp_erp_action
  1229. * Returns: 0 on success, error otherwise
  1230. */
  1231. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1232. {
  1233. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1234. struct zfcp_port *port = erp_action->port;
  1235. struct zfcp_fsf_req *req;
  1236. int retval = -EIO;
  1237. spin_lock_bh(&qdio->req_q_lock);
  1238. if (zfcp_qdio_sbal_get(qdio))
  1239. goto out;
  1240. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1241. SBAL_FLAGS0_TYPE_READ,
  1242. qdio->adapter->pool.erp_req);
  1243. if (IS_ERR(req)) {
  1244. retval = PTR_ERR(req);
  1245. goto out;
  1246. }
  1247. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1248. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1249. req->handler = zfcp_fsf_open_port_handler;
  1250. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1251. req->data = port;
  1252. req->erp_action = erp_action;
  1253. erp_action->fsf_req_id = req->req_id;
  1254. get_device(&port->dev);
  1255. zfcp_fsf_start_erp_timer(req);
  1256. retval = zfcp_fsf_req_send(req);
  1257. if (retval) {
  1258. zfcp_fsf_req_free(req);
  1259. erp_action->fsf_req_id = 0;
  1260. put_device(&port->dev);
  1261. }
  1262. out:
  1263. spin_unlock_bh(&qdio->req_q_lock);
  1264. return retval;
  1265. }
  1266. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1267. {
  1268. struct zfcp_port *port = req->data;
  1269. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1270. return;
  1271. switch (req->qtcb->header.fsf_status) {
  1272. case FSF_PORT_HANDLE_NOT_VALID:
  1273. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1274. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1275. break;
  1276. case FSF_ADAPTER_STATUS_AVAILABLE:
  1277. break;
  1278. case FSF_GOOD:
  1279. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1280. ZFCP_STATUS_COMMON_OPEN,
  1281. ZFCP_CLEAR);
  1282. break;
  1283. }
  1284. }
  1285. /**
  1286. * zfcp_fsf_close_port - create and send close port request
  1287. * @erp_action: pointer to struct zfcp_erp_action
  1288. * Returns: 0 on success, error otherwise
  1289. */
  1290. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1291. {
  1292. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1293. struct zfcp_fsf_req *req;
  1294. int retval = -EIO;
  1295. spin_lock_bh(&qdio->req_q_lock);
  1296. if (zfcp_qdio_sbal_get(qdio))
  1297. goto out;
  1298. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1299. SBAL_FLAGS0_TYPE_READ,
  1300. qdio->adapter->pool.erp_req);
  1301. if (IS_ERR(req)) {
  1302. retval = PTR_ERR(req);
  1303. goto out;
  1304. }
  1305. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1306. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1307. req->handler = zfcp_fsf_close_port_handler;
  1308. req->data = erp_action->port;
  1309. req->erp_action = erp_action;
  1310. req->qtcb->header.port_handle = erp_action->port->handle;
  1311. erp_action->fsf_req_id = req->req_id;
  1312. zfcp_fsf_start_erp_timer(req);
  1313. retval = zfcp_fsf_req_send(req);
  1314. if (retval) {
  1315. zfcp_fsf_req_free(req);
  1316. erp_action->fsf_req_id = 0;
  1317. }
  1318. out:
  1319. spin_unlock_bh(&qdio->req_q_lock);
  1320. return retval;
  1321. }
  1322. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1323. {
  1324. struct zfcp_fc_wka_port *wka_port = req->data;
  1325. struct fsf_qtcb_header *header = &req->qtcb->header;
  1326. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1327. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1328. goto out;
  1329. }
  1330. switch (header->fsf_status) {
  1331. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1332. dev_warn(&req->adapter->ccw_device->dev,
  1333. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1334. /* fall through */
  1335. case FSF_ADAPTER_STATUS_AVAILABLE:
  1336. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1337. /* fall through */
  1338. case FSF_ACCESS_DENIED:
  1339. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1340. break;
  1341. case FSF_GOOD:
  1342. wka_port->handle = header->port_handle;
  1343. /* fall through */
  1344. case FSF_PORT_ALREADY_OPEN:
  1345. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1346. }
  1347. out:
  1348. wake_up(&wka_port->completion_wq);
  1349. }
  1350. /**
  1351. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1352. * @wka_port: pointer to struct zfcp_fc_wka_port
  1353. * Returns: 0 on success, error otherwise
  1354. */
  1355. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1356. {
  1357. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1358. struct zfcp_fsf_req *req;
  1359. int retval = -EIO;
  1360. spin_lock_bh(&qdio->req_q_lock);
  1361. if (zfcp_qdio_sbal_get(qdio))
  1362. goto out;
  1363. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1364. SBAL_FLAGS0_TYPE_READ,
  1365. qdio->adapter->pool.erp_req);
  1366. if (unlikely(IS_ERR(req))) {
  1367. retval = PTR_ERR(req);
  1368. goto out;
  1369. }
  1370. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1371. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1372. req->handler = zfcp_fsf_open_wka_port_handler;
  1373. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1374. req->data = wka_port;
  1375. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1376. retval = zfcp_fsf_req_send(req);
  1377. if (retval)
  1378. zfcp_fsf_req_free(req);
  1379. out:
  1380. spin_unlock_bh(&qdio->req_q_lock);
  1381. return retval;
  1382. }
  1383. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1384. {
  1385. struct zfcp_fc_wka_port *wka_port = req->data;
  1386. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1387. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1388. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1389. }
  1390. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1391. wake_up(&wka_port->completion_wq);
  1392. }
  1393. /**
  1394. * zfcp_fsf_close_wka_port - create and send close wka port request
  1395. * @wka_port: WKA port to open
  1396. * Returns: 0 on success, error otherwise
  1397. */
  1398. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1399. {
  1400. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1401. struct zfcp_fsf_req *req;
  1402. int retval = -EIO;
  1403. spin_lock_bh(&qdio->req_q_lock);
  1404. if (zfcp_qdio_sbal_get(qdio))
  1405. goto out;
  1406. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1407. SBAL_FLAGS0_TYPE_READ,
  1408. qdio->adapter->pool.erp_req);
  1409. if (unlikely(IS_ERR(req))) {
  1410. retval = PTR_ERR(req);
  1411. goto out;
  1412. }
  1413. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1414. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1415. req->handler = zfcp_fsf_close_wka_port_handler;
  1416. req->data = wka_port;
  1417. req->qtcb->header.port_handle = wka_port->handle;
  1418. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1419. retval = zfcp_fsf_req_send(req);
  1420. if (retval)
  1421. zfcp_fsf_req_free(req);
  1422. out:
  1423. spin_unlock_bh(&qdio->req_q_lock);
  1424. return retval;
  1425. }
  1426. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1427. {
  1428. struct zfcp_port *port = req->data;
  1429. struct fsf_qtcb_header *header = &req->qtcb->header;
  1430. struct zfcp_unit *unit;
  1431. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1432. return;
  1433. switch (header->fsf_status) {
  1434. case FSF_PORT_HANDLE_NOT_VALID:
  1435. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1436. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1437. break;
  1438. case FSF_ACCESS_DENIED:
  1439. zfcp_fsf_access_denied_port(req, port);
  1440. break;
  1441. case FSF_PORT_BOXED:
  1442. /* can't use generic zfcp_erp_modify_port_status because
  1443. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1444. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1445. read_lock(&port->unit_list_lock);
  1446. list_for_each_entry(unit, &port->unit_list, list)
  1447. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1448. &unit->status);
  1449. read_unlock(&port->unit_list_lock);
  1450. zfcp_erp_port_boxed(port, "fscpph2", req);
  1451. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1452. break;
  1453. case FSF_ADAPTER_STATUS_AVAILABLE:
  1454. switch (header->fsf_status_qual.word[0]) {
  1455. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1456. /* fall through */
  1457. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1458. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1459. break;
  1460. }
  1461. break;
  1462. case FSF_GOOD:
  1463. /* can't use generic zfcp_erp_modify_port_status because
  1464. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1465. */
  1466. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1467. read_lock(&port->unit_list_lock);
  1468. list_for_each_entry(unit, &port->unit_list, list)
  1469. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1470. &unit->status);
  1471. read_unlock(&port->unit_list_lock);
  1472. break;
  1473. }
  1474. }
  1475. /**
  1476. * zfcp_fsf_close_physical_port - close physical port
  1477. * @erp_action: pointer to struct zfcp_erp_action
  1478. * Returns: 0 on success
  1479. */
  1480. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1481. {
  1482. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1483. struct zfcp_fsf_req *req;
  1484. int retval = -EIO;
  1485. spin_lock_bh(&qdio->req_q_lock);
  1486. if (zfcp_qdio_sbal_get(qdio))
  1487. goto out;
  1488. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1489. SBAL_FLAGS0_TYPE_READ,
  1490. qdio->adapter->pool.erp_req);
  1491. if (IS_ERR(req)) {
  1492. retval = PTR_ERR(req);
  1493. goto out;
  1494. }
  1495. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1496. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1497. req->data = erp_action->port;
  1498. req->qtcb->header.port_handle = erp_action->port->handle;
  1499. req->erp_action = erp_action;
  1500. req->handler = zfcp_fsf_close_physical_port_handler;
  1501. erp_action->fsf_req_id = req->req_id;
  1502. zfcp_fsf_start_erp_timer(req);
  1503. retval = zfcp_fsf_req_send(req);
  1504. if (retval) {
  1505. zfcp_fsf_req_free(req);
  1506. erp_action->fsf_req_id = 0;
  1507. }
  1508. out:
  1509. spin_unlock_bh(&qdio->req_q_lock);
  1510. return retval;
  1511. }
  1512. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1513. {
  1514. struct zfcp_adapter *adapter = req->adapter;
  1515. struct zfcp_unit *unit = req->data;
  1516. struct fsf_qtcb_header *header = &req->qtcb->header;
  1517. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1518. struct fsf_queue_designator *queue_designator =
  1519. &header->fsf_status_qual.fsf_queue_designator;
  1520. int exclusive, readwrite;
  1521. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1522. return;
  1523. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1524. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1525. ZFCP_STATUS_UNIT_SHARED |
  1526. ZFCP_STATUS_UNIT_READONLY,
  1527. &unit->status);
  1528. switch (header->fsf_status) {
  1529. case FSF_PORT_HANDLE_NOT_VALID:
  1530. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1531. /* fall through */
  1532. case FSF_LUN_ALREADY_OPEN:
  1533. break;
  1534. case FSF_ACCESS_DENIED:
  1535. zfcp_fsf_access_denied_unit(req, unit);
  1536. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1537. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1538. break;
  1539. case FSF_PORT_BOXED:
  1540. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1541. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1542. break;
  1543. case FSF_LUN_SHARING_VIOLATION:
  1544. if (header->fsf_status_qual.word[0])
  1545. dev_warn(&adapter->ccw_device->dev,
  1546. "LUN 0x%Lx on port 0x%Lx is already in "
  1547. "use by CSS%d, MIF Image ID %x\n",
  1548. (unsigned long long)unit->fcp_lun,
  1549. (unsigned long long)unit->port->wwpn,
  1550. queue_designator->cssid,
  1551. queue_designator->hla);
  1552. else
  1553. zfcp_act_eval_err(adapter,
  1554. header->fsf_status_qual.word[2]);
  1555. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1556. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1557. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1558. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1559. break;
  1560. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1561. dev_warn(&adapter->ccw_device->dev,
  1562. "No handle is available for LUN "
  1563. "0x%016Lx on port 0x%016Lx\n",
  1564. (unsigned long long)unit->fcp_lun,
  1565. (unsigned long long)unit->port->wwpn);
  1566. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1567. /* fall through */
  1568. case FSF_INVALID_COMMAND_OPTION:
  1569. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1570. break;
  1571. case FSF_ADAPTER_STATUS_AVAILABLE:
  1572. switch (header->fsf_status_qual.word[0]) {
  1573. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1574. zfcp_fc_test_link(unit->port);
  1575. /* fall through */
  1576. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1577. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1578. break;
  1579. }
  1580. break;
  1581. case FSF_GOOD:
  1582. unit->handle = header->lun_handle;
  1583. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1584. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1585. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1586. !zfcp_ccw_priv_sch(adapter)) {
  1587. exclusive = (bottom->lun_access_info &
  1588. FSF_UNIT_ACCESS_EXCLUSIVE);
  1589. readwrite = (bottom->lun_access_info &
  1590. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1591. if (!exclusive)
  1592. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1593. &unit->status);
  1594. if (!readwrite) {
  1595. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1596. &unit->status);
  1597. dev_info(&adapter->ccw_device->dev,
  1598. "SCSI device at LUN 0x%016Lx on port "
  1599. "0x%016Lx opened read-only\n",
  1600. (unsigned long long)unit->fcp_lun,
  1601. (unsigned long long)unit->port->wwpn);
  1602. }
  1603. if (exclusive && !readwrite) {
  1604. dev_err(&adapter->ccw_device->dev,
  1605. "Exclusive read-only access not "
  1606. "supported (unit 0x%016Lx, "
  1607. "port 0x%016Lx)\n",
  1608. (unsigned long long)unit->fcp_lun,
  1609. (unsigned long long)unit->port->wwpn);
  1610. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1611. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1612. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1613. } else if (!exclusive && readwrite) {
  1614. dev_err(&adapter->ccw_device->dev,
  1615. "Shared read-write access not "
  1616. "supported (unit 0x%016Lx, port "
  1617. "0x%016Lx)\n",
  1618. (unsigned long long)unit->fcp_lun,
  1619. (unsigned long long)unit->port->wwpn);
  1620. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1621. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1622. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1623. }
  1624. }
  1625. break;
  1626. }
  1627. }
  1628. /**
  1629. * zfcp_fsf_open_unit - open unit
  1630. * @erp_action: pointer to struct zfcp_erp_action
  1631. * Returns: 0 on success, error otherwise
  1632. */
  1633. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1634. {
  1635. struct zfcp_adapter *adapter = erp_action->adapter;
  1636. struct zfcp_qdio *qdio = adapter->qdio;
  1637. struct zfcp_fsf_req *req;
  1638. int retval = -EIO;
  1639. spin_lock_bh(&qdio->req_q_lock);
  1640. if (zfcp_qdio_sbal_get(qdio))
  1641. goto out;
  1642. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1643. SBAL_FLAGS0_TYPE_READ,
  1644. adapter->pool.erp_req);
  1645. if (IS_ERR(req)) {
  1646. retval = PTR_ERR(req);
  1647. goto out;
  1648. }
  1649. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1650. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1651. req->qtcb->header.port_handle = erp_action->port->handle;
  1652. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1653. req->handler = zfcp_fsf_open_unit_handler;
  1654. req->data = erp_action->unit;
  1655. req->erp_action = erp_action;
  1656. erp_action->fsf_req_id = req->req_id;
  1657. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1658. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1659. zfcp_fsf_start_erp_timer(req);
  1660. retval = zfcp_fsf_req_send(req);
  1661. if (retval) {
  1662. zfcp_fsf_req_free(req);
  1663. erp_action->fsf_req_id = 0;
  1664. }
  1665. out:
  1666. spin_unlock_bh(&qdio->req_q_lock);
  1667. return retval;
  1668. }
  1669. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1670. {
  1671. struct zfcp_unit *unit = req->data;
  1672. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1673. return;
  1674. switch (req->qtcb->header.fsf_status) {
  1675. case FSF_PORT_HANDLE_NOT_VALID:
  1676. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1677. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1678. break;
  1679. case FSF_LUN_HANDLE_NOT_VALID:
  1680. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1681. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1682. break;
  1683. case FSF_PORT_BOXED:
  1684. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1685. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1686. break;
  1687. case FSF_ADAPTER_STATUS_AVAILABLE:
  1688. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1689. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1690. zfcp_fc_test_link(unit->port);
  1691. /* fall through */
  1692. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1693. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1694. break;
  1695. }
  1696. break;
  1697. case FSF_GOOD:
  1698. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1699. break;
  1700. }
  1701. }
  1702. /**
  1703. * zfcp_fsf_close_unit - close zfcp unit
  1704. * @erp_action: pointer to struct zfcp_unit
  1705. * Returns: 0 on success, error otherwise
  1706. */
  1707. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1708. {
  1709. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1710. struct zfcp_fsf_req *req;
  1711. int retval = -EIO;
  1712. spin_lock_bh(&qdio->req_q_lock);
  1713. if (zfcp_qdio_sbal_get(qdio))
  1714. goto out;
  1715. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1716. SBAL_FLAGS0_TYPE_READ,
  1717. qdio->adapter->pool.erp_req);
  1718. if (IS_ERR(req)) {
  1719. retval = PTR_ERR(req);
  1720. goto out;
  1721. }
  1722. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1723. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1724. req->qtcb->header.port_handle = erp_action->port->handle;
  1725. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1726. req->handler = zfcp_fsf_close_unit_handler;
  1727. req->data = erp_action->unit;
  1728. req->erp_action = erp_action;
  1729. erp_action->fsf_req_id = req->req_id;
  1730. zfcp_fsf_start_erp_timer(req);
  1731. retval = zfcp_fsf_req_send(req);
  1732. if (retval) {
  1733. zfcp_fsf_req_free(req);
  1734. erp_action->fsf_req_id = 0;
  1735. }
  1736. out:
  1737. spin_unlock_bh(&qdio->req_q_lock);
  1738. return retval;
  1739. }
  1740. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1741. {
  1742. lat_rec->sum += lat;
  1743. lat_rec->min = min(lat_rec->min, lat);
  1744. lat_rec->max = max(lat_rec->max, lat);
  1745. }
  1746. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1747. {
  1748. struct fsf_qual_latency_info *lat_in;
  1749. struct latency_cont *lat = NULL;
  1750. struct zfcp_unit *unit = req->unit;
  1751. struct zfcp_blk_drv_data blktrc;
  1752. int ticks = req->adapter->timer_ticks;
  1753. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1754. blktrc.flags = 0;
  1755. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1756. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1757. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1758. blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
  1759. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1760. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1761. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1762. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1763. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1764. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1765. switch (req->qtcb->bottom.io.data_direction) {
  1766. case FSF_DATADIR_READ:
  1767. lat = &unit->latencies.read;
  1768. break;
  1769. case FSF_DATADIR_WRITE:
  1770. lat = &unit->latencies.write;
  1771. break;
  1772. case FSF_DATADIR_CMND:
  1773. lat = &unit->latencies.cmd;
  1774. break;
  1775. }
  1776. if (lat) {
  1777. spin_lock(&unit->latencies.lock);
  1778. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1779. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1780. lat->counter++;
  1781. spin_unlock(&unit->latencies.lock);
  1782. }
  1783. }
  1784. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1785. sizeof(blktrc));
  1786. }
  1787. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1788. {
  1789. struct scsi_cmnd *scpnt;
  1790. struct fcp_resp_with_ext *fcp_rsp;
  1791. unsigned long flags;
  1792. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1793. scpnt = req->data;
  1794. if (unlikely(!scpnt)) {
  1795. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1796. return;
  1797. }
  1798. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1799. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1800. goto skip_fsfstatus;
  1801. }
  1802. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1803. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1804. skip_fsfstatus:
  1805. zfcp_fsf_req_trace(req, scpnt);
  1806. zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
  1807. scpnt->host_scribble = NULL;
  1808. (scpnt->scsi_done) (scpnt);
  1809. /*
  1810. * We must hold this lock until scsi_done has been called.
  1811. * Otherwise we may call scsi_done after abort regarding this
  1812. * command has completed.
  1813. * Note: scsi_done must not block!
  1814. */
  1815. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1816. }
  1817. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1818. {
  1819. struct fcp_resp_with_ext *fcp_rsp;
  1820. struct fcp_resp_rsp_info *rsp_info;
  1821. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1822. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1823. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1824. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1825. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1826. }
  1827. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1828. {
  1829. struct zfcp_unit *unit;
  1830. struct fsf_qtcb_header *header = &req->qtcb->header;
  1831. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1832. unit = req->data;
  1833. else
  1834. unit = req->unit;
  1835. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1836. goto skip_fsfstatus;
  1837. switch (header->fsf_status) {
  1838. case FSF_HANDLE_MISMATCH:
  1839. case FSF_PORT_HANDLE_NOT_VALID:
  1840. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1841. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1842. break;
  1843. case FSF_FCPLUN_NOT_VALID:
  1844. case FSF_LUN_HANDLE_NOT_VALID:
  1845. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1846. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1847. break;
  1848. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1849. zfcp_fsf_class_not_supp(req);
  1850. break;
  1851. case FSF_ACCESS_DENIED:
  1852. zfcp_fsf_access_denied_unit(req, unit);
  1853. break;
  1854. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1855. dev_err(&req->adapter->ccw_device->dev,
  1856. "Incorrect direction %d, unit 0x%016Lx on port "
  1857. "0x%016Lx closed\n",
  1858. req->qtcb->bottom.io.data_direction,
  1859. (unsigned long long)unit->fcp_lun,
  1860. (unsigned long long)unit->port->wwpn);
  1861. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1862. req);
  1863. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1864. break;
  1865. case FSF_CMND_LENGTH_NOT_VALID:
  1866. dev_err(&req->adapter->ccw_device->dev,
  1867. "Incorrect CDB length %d, unit 0x%016Lx on "
  1868. "port 0x%016Lx closed\n",
  1869. req->qtcb->bottom.io.fcp_cmnd_length,
  1870. (unsigned long long)unit->fcp_lun,
  1871. (unsigned long long)unit->port->wwpn);
  1872. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1873. req);
  1874. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1875. break;
  1876. case FSF_PORT_BOXED:
  1877. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1878. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1879. break;
  1880. case FSF_LUN_BOXED:
  1881. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1882. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1883. break;
  1884. case FSF_ADAPTER_STATUS_AVAILABLE:
  1885. if (header->fsf_status_qual.word[0] ==
  1886. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1887. zfcp_fc_test_link(unit->port);
  1888. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1889. break;
  1890. }
  1891. skip_fsfstatus:
  1892. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1893. zfcp_fsf_send_fcp_ctm_handler(req);
  1894. else {
  1895. zfcp_fsf_send_fcp_command_task_handler(req);
  1896. req->unit = NULL;
  1897. put_device(&unit->dev);
  1898. }
  1899. }
  1900. /**
  1901. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1902. * @unit: unit where command is sent to
  1903. * @scsi_cmnd: scsi command to be sent
  1904. */
  1905. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  1906. struct scsi_cmnd *scsi_cmnd)
  1907. {
  1908. struct zfcp_fsf_req *req;
  1909. struct fcp_cmnd *fcp_cmnd;
  1910. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  1911. int real_bytes, retval = -EIO;
  1912. struct zfcp_adapter *adapter = unit->port->adapter;
  1913. struct zfcp_qdio *qdio = adapter->qdio;
  1914. if (unlikely(!(atomic_read(&unit->status) &
  1915. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1916. return -EBUSY;
  1917. spin_lock(&qdio->req_q_lock);
  1918. if (atomic_read(&qdio->req_q.count) <= 0) {
  1919. atomic_inc(&qdio->req_q_full);
  1920. goto out;
  1921. }
  1922. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1923. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  1924. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1925. sbtype, adapter->pool.scsi_req);
  1926. if (IS_ERR(req)) {
  1927. retval = PTR_ERR(req);
  1928. goto out;
  1929. }
  1930. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1931. req->unit = unit;
  1932. req->data = scsi_cmnd;
  1933. req->handler = zfcp_fsf_send_fcp_command_handler;
  1934. req->qtcb->header.lun_handle = unit->handle;
  1935. req->qtcb->header.port_handle = unit->port->handle;
  1936. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  1937. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  1938. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1939. /*
  1940. * set depending on data direction:
  1941. * data direction bits in SBALE (SB Type)
  1942. * data direction bits in QTCB
  1943. */
  1944. switch (scsi_cmnd->sc_data_direction) {
  1945. case DMA_NONE:
  1946. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  1947. break;
  1948. case DMA_FROM_DEVICE:
  1949. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  1950. break;
  1951. case DMA_TO_DEVICE:
  1952. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  1953. break;
  1954. case DMA_BIDIRECTIONAL:
  1955. goto failed_scsi_cmnd;
  1956. }
  1957. get_device(&unit->dev);
  1958. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1959. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
  1960. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1961. scsi_sglist(scsi_cmnd),
  1962. ZFCP_FSF_MAX_SBALS_PER_REQ);
  1963. if (unlikely(real_bytes < 0)) {
  1964. if (req->qdio_req.sbal_number >= ZFCP_FSF_MAX_SBALS_PER_REQ) {
  1965. dev_err(&adapter->ccw_device->dev,
  1966. "Oversize data package, unit 0x%016Lx "
  1967. "on port 0x%016Lx closed\n",
  1968. (unsigned long long)unit->fcp_lun,
  1969. (unsigned long long)unit->port->wwpn);
  1970. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  1971. retval = -EINVAL;
  1972. }
  1973. goto failed_scsi_cmnd;
  1974. }
  1975. retval = zfcp_fsf_req_send(req);
  1976. if (unlikely(retval))
  1977. goto failed_scsi_cmnd;
  1978. goto out;
  1979. failed_scsi_cmnd:
  1980. put_device(&unit->dev);
  1981. zfcp_fsf_req_free(req);
  1982. scsi_cmnd->host_scribble = NULL;
  1983. out:
  1984. spin_unlock(&qdio->req_q_lock);
  1985. return retval;
  1986. }
  1987. /**
  1988. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  1989. * @unit: pointer to struct zfcp_unit
  1990. * @tm_flags: unsigned byte for task management flags
  1991. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1992. */
  1993. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  1994. {
  1995. struct zfcp_fsf_req *req = NULL;
  1996. struct fcp_cmnd *fcp_cmnd;
  1997. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  1998. if (unlikely(!(atomic_read(&unit->status) &
  1999. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2000. return NULL;
  2001. spin_lock_bh(&qdio->req_q_lock);
  2002. if (zfcp_qdio_sbal_get(qdio))
  2003. goto out;
  2004. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2005. SBAL_FLAGS0_TYPE_WRITE,
  2006. qdio->adapter->pool.scsi_req);
  2007. if (IS_ERR(req)) {
  2008. req = NULL;
  2009. goto out;
  2010. }
  2011. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2012. req->data = unit;
  2013. req->handler = zfcp_fsf_send_fcp_command_handler;
  2014. req->qtcb->header.lun_handle = unit->handle;
  2015. req->qtcb->header.port_handle = unit->port->handle;
  2016. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2017. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2018. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2019. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2020. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2021. zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
  2022. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2023. if (!zfcp_fsf_req_send(req))
  2024. goto out;
  2025. zfcp_fsf_req_free(req);
  2026. req = NULL;
  2027. out:
  2028. spin_unlock_bh(&qdio->req_q_lock);
  2029. return req;
  2030. }
  2031. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2032. {
  2033. }
  2034. /**
  2035. * zfcp_fsf_control_file - control file upload/download
  2036. * @adapter: pointer to struct zfcp_adapter
  2037. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2038. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2039. */
  2040. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2041. struct zfcp_fsf_cfdc *fsf_cfdc)
  2042. {
  2043. struct zfcp_qdio *qdio = adapter->qdio;
  2044. struct zfcp_fsf_req *req = NULL;
  2045. struct fsf_qtcb_bottom_support *bottom;
  2046. int direction, retval = -EIO, bytes;
  2047. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2048. return ERR_PTR(-EOPNOTSUPP);
  2049. switch (fsf_cfdc->command) {
  2050. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2051. direction = SBAL_FLAGS0_TYPE_WRITE;
  2052. break;
  2053. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2054. direction = SBAL_FLAGS0_TYPE_READ;
  2055. break;
  2056. default:
  2057. return ERR_PTR(-EINVAL);
  2058. }
  2059. spin_lock_bh(&qdio->req_q_lock);
  2060. if (zfcp_qdio_sbal_get(qdio))
  2061. goto out;
  2062. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
  2063. if (IS_ERR(req)) {
  2064. retval = -EPERM;
  2065. goto out;
  2066. }
  2067. req->handler = zfcp_fsf_control_file_handler;
  2068. bottom = &req->qtcb->bottom.support;
  2069. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2070. bottom->option = fsf_cfdc->option;
  2071. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  2072. fsf_cfdc->sg,
  2073. ZFCP_FSF_MAX_SBALS_PER_REQ);
  2074. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2075. zfcp_fsf_req_free(req);
  2076. goto out;
  2077. }
  2078. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2079. retval = zfcp_fsf_req_send(req);
  2080. out:
  2081. spin_unlock_bh(&qdio->req_q_lock);
  2082. if (!retval) {
  2083. wait_for_completion(&req->completion);
  2084. return req;
  2085. }
  2086. return ERR_PTR(retval);
  2087. }
  2088. /**
  2089. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2090. * @adapter: pointer to struct zfcp_adapter
  2091. * @sbal_idx: response queue index of SBAL to be processed
  2092. */
  2093. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2094. {
  2095. struct zfcp_adapter *adapter = qdio->adapter;
  2096. struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
  2097. struct qdio_buffer_element *sbale;
  2098. struct zfcp_fsf_req *fsf_req;
  2099. unsigned long req_id;
  2100. int idx;
  2101. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2102. sbale = &sbal->element[idx];
  2103. req_id = (unsigned long) sbale->addr;
  2104. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2105. if (!fsf_req)
  2106. /*
  2107. * Unknown request means that we have potentially memory
  2108. * corruption and must stop the machine immediately.
  2109. */
  2110. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2111. req_id, dev_name(&adapter->ccw_device->dev));
  2112. fsf_req->qdio_req.sbal_response = sbal_idx;
  2113. fsf_req->qdio_req.qdio_inb_usage =
  2114. atomic_read(&qdio->resp_q.count);
  2115. zfcp_fsf_req_complete(fsf_req);
  2116. if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
  2117. break;
  2118. }
  2119. }