zfcp_fsf.c 66 KB

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